How to solve this error `sudo: /usr/local/bin/sudo must be owned by uid 0 and have the setuid bit set`...












1















TLDR: I am running Ubuntu 18.04 with i3 and I messed up my permissions. Whenever I run a command with sudo, I get this error message, sudo: /usr/local/bin/sudo must be owned by uid 0 and have the setuid bit set. I am trying to figure out if I need to fully re-install Ubuntu or if this can be fixed in a less drastic way.



What had happened was: I was trying to upgrade my npm version with nvm and the nvm command was not being recognized. I followed this stackoverflow post's instructions https://stackoverflow.com/questions/21215059/cant-use-nvm-from-root-or-sudo to copy the version of node I had active via nvm into the /usr/local. I ran the below. (Yes, I realize now that I should have investigated this series of commands before running them.)



n=$(which node); 
n=${n%/bin/node};
chmod -R 755 $n/bin/*;
sudo cp -r $n/{bin,lib,share} /usr/local


I then got tons of errors saying
chmod: changing permissions of '/usr/bin/*': Operation not permitted



After that I ran sudo nvm install-latest-npm and got the same error as I had before, sudo: nvm: command not found.



Then I tried running another command with sudo, and got the error sudo: /usr/local/bin/sudo must be owned by uid 0 and have the setuid bit set. I now get this error whenever I run anything with sudo.



I think this problem was caused by me running chmod -R 755 $n/bin/*; but I'm confused because the error message said permissions for /usr/bin were not changed.

I have a two-part question:
1) What caused this error? Am I correct that it was caused by the chmod -R command?
2) Can I fix this without completely reinstalling ubuntu? If so, how?



For context, I already read these two questions sudo: /usr/lib/sudo/sudoers.so must be owned by uid 0 and this /usr/bin/sudo must be owned by uid 0 and have the setuid bit set. However, I am not sure if the advice from the first question's answer applies to this situation, because the error message I receive is not referring specifically to /usr/lib/sudo/sudoers.so.



Thanks for reading!










share|improve this question


















  • 2





    Possibly a more relevant previous question is What if I accidentally run command “chmod -R” on system directories (/, /etc, …)

    – steeldriver
    Jan 9 at 0:59











  • Possible solution: askubuntu.com/a/634013/231142

    – Terrance
    Jan 9 at 4:20
















1















TLDR: I am running Ubuntu 18.04 with i3 and I messed up my permissions. Whenever I run a command with sudo, I get this error message, sudo: /usr/local/bin/sudo must be owned by uid 0 and have the setuid bit set. I am trying to figure out if I need to fully re-install Ubuntu or if this can be fixed in a less drastic way.



What had happened was: I was trying to upgrade my npm version with nvm and the nvm command was not being recognized. I followed this stackoverflow post's instructions https://stackoverflow.com/questions/21215059/cant-use-nvm-from-root-or-sudo to copy the version of node I had active via nvm into the /usr/local. I ran the below. (Yes, I realize now that I should have investigated this series of commands before running them.)



n=$(which node); 
n=${n%/bin/node};
chmod -R 755 $n/bin/*;
sudo cp -r $n/{bin,lib,share} /usr/local


I then got tons of errors saying
chmod: changing permissions of '/usr/bin/*': Operation not permitted



After that I ran sudo nvm install-latest-npm and got the same error as I had before, sudo: nvm: command not found.



Then I tried running another command with sudo, and got the error sudo: /usr/local/bin/sudo must be owned by uid 0 and have the setuid bit set. I now get this error whenever I run anything with sudo.



I think this problem was caused by me running chmod -R 755 $n/bin/*; but I'm confused because the error message said permissions for /usr/bin were not changed.

I have a two-part question:
1) What caused this error? Am I correct that it was caused by the chmod -R command?
2) Can I fix this without completely reinstalling ubuntu? If so, how?



For context, I already read these two questions sudo: /usr/lib/sudo/sudoers.so must be owned by uid 0 and this /usr/bin/sudo must be owned by uid 0 and have the setuid bit set. However, I am not sure if the advice from the first question's answer applies to this situation, because the error message I receive is not referring specifically to /usr/lib/sudo/sudoers.so.



Thanks for reading!










share|improve this question


















  • 2





    Possibly a more relevant previous question is What if I accidentally run command “chmod -R” on system directories (/, /etc, …)

    – steeldriver
    Jan 9 at 0:59











  • Possible solution: askubuntu.com/a/634013/231142

    – Terrance
    Jan 9 at 4:20














1












1








1








TLDR: I am running Ubuntu 18.04 with i3 and I messed up my permissions. Whenever I run a command with sudo, I get this error message, sudo: /usr/local/bin/sudo must be owned by uid 0 and have the setuid bit set. I am trying to figure out if I need to fully re-install Ubuntu or if this can be fixed in a less drastic way.



What had happened was: I was trying to upgrade my npm version with nvm and the nvm command was not being recognized. I followed this stackoverflow post's instructions https://stackoverflow.com/questions/21215059/cant-use-nvm-from-root-or-sudo to copy the version of node I had active via nvm into the /usr/local. I ran the below. (Yes, I realize now that I should have investigated this series of commands before running them.)



n=$(which node); 
n=${n%/bin/node};
chmod -R 755 $n/bin/*;
sudo cp -r $n/{bin,lib,share} /usr/local


I then got tons of errors saying
chmod: changing permissions of '/usr/bin/*': Operation not permitted



After that I ran sudo nvm install-latest-npm and got the same error as I had before, sudo: nvm: command not found.



Then I tried running another command with sudo, and got the error sudo: /usr/local/bin/sudo must be owned by uid 0 and have the setuid bit set. I now get this error whenever I run anything with sudo.



I think this problem was caused by me running chmod -R 755 $n/bin/*; but I'm confused because the error message said permissions for /usr/bin were not changed.

I have a two-part question:
1) What caused this error? Am I correct that it was caused by the chmod -R command?
2) Can I fix this without completely reinstalling ubuntu? If so, how?



For context, I already read these two questions sudo: /usr/lib/sudo/sudoers.so must be owned by uid 0 and this /usr/bin/sudo must be owned by uid 0 and have the setuid bit set. However, I am not sure if the advice from the first question's answer applies to this situation, because the error message I receive is not referring specifically to /usr/lib/sudo/sudoers.so.



Thanks for reading!










share|improve this question














TLDR: I am running Ubuntu 18.04 with i3 and I messed up my permissions. Whenever I run a command with sudo, I get this error message, sudo: /usr/local/bin/sudo must be owned by uid 0 and have the setuid bit set. I am trying to figure out if I need to fully re-install Ubuntu or if this can be fixed in a less drastic way.



What had happened was: I was trying to upgrade my npm version with nvm and the nvm command was not being recognized. I followed this stackoverflow post's instructions https://stackoverflow.com/questions/21215059/cant-use-nvm-from-root-or-sudo to copy the version of node I had active via nvm into the /usr/local. I ran the below. (Yes, I realize now that I should have investigated this series of commands before running them.)



n=$(which node); 
n=${n%/bin/node};
chmod -R 755 $n/bin/*;
sudo cp -r $n/{bin,lib,share} /usr/local


I then got tons of errors saying
chmod: changing permissions of '/usr/bin/*': Operation not permitted



After that I ran sudo nvm install-latest-npm and got the same error as I had before, sudo: nvm: command not found.



Then I tried running another command with sudo, and got the error sudo: /usr/local/bin/sudo must be owned by uid 0 and have the setuid bit set. I now get this error whenever I run anything with sudo.



I think this problem was caused by me running chmod -R 755 $n/bin/*; but I'm confused because the error message said permissions for /usr/bin were not changed.

I have a two-part question:
1) What caused this error? Am I correct that it was caused by the chmod -R command?
2) Can I fix this without completely reinstalling ubuntu? If so, how?



For context, I already read these two questions sudo: /usr/lib/sudo/sudoers.so must be owned by uid 0 and this /usr/bin/sudo must be owned by uid 0 and have the setuid bit set. However, I am not sure if the advice from the first question's answer applies to this situation, because the error message I receive is not referring specifically to /usr/lib/sudo/sudoers.so.



Thanks for reading!







command-line bash permissions sudo chmod






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 9 at 0:49









ByteByByteByteByByte

61




61








  • 2





    Possibly a more relevant previous question is What if I accidentally run command “chmod -R” on system directories (/, /etc, …)

    – steeldriver
    Jan 9 at 0:59











  • Possible solution: askubuntu.com/a/634013/231142

    – Terrance
    Jan 9 at 4:20














  • 2





    Possibly a more relevant previous question is What if I accidentally run command “chmod -R” on system directories (/, /etc, …)

    – steeldriver
    Jan 9 at 0:59











  • Possible solution: askubuntu.com/a/634013/231142

    – Terrance
    Jan 9 at 4:20








2




2





Possibly a more relevant previous question is What if I accidentally run command “chmod -R” on system directories (/, /etc, …)

– steeldriver
Jan 9 at 0:59





Possibly a more relevant previous question is What if I accidentally run command “chmod -R” on system directories (/, /etc, …)

– steeldriver
Jan 9 at 0:59













Possible solution: askubuntu.com/a/634013/231142

– Terrance
Jan 9 at 4:20





Possible solution: askubuntu.com/a/634013/231142

– Terrance
Jan 9 at 4:20










1 Answer
1






active

oldest

votes


















1














must be owned by uid 0 and have the setuid bit set





  1. Check the current owner and permissions with ls -l /usr/bin/sudo. It should similar to:



    -rwsr-xr-x 1 root root 157192 2018-08-23 10:36:40 /usr/bin/sudo



  2. Run pkexec bash in a terminal to get a shell with root permissions.



  3. Fix ownership of the file:



    chown root:root /usr/bin/sudo



  4. Set the setuid bit:



    chmod u+s /usr/bin/sudo


  5. sudo should now be available for you to make further repairs.







share|improve this answer


























  • Pretty good thinking! Back when I wrote my answer I didn't even know about pkexec. I sure do now! Great answer!

    – Terrance
    Jan 9 at 14:28











  • @xiota Thank you for this very thorough response. When I checked the current owner and permissions, it was extremely similar to what you showed, -rwsr-xr-x 1 root root 149080 Jan 17 2018 /usr/bin/sudo. However, when I ran pkexec bash, I got an error message, pkexec must be setuid root. Since I wasn't able to get a shell with root permissions, I am going to boot up in recovery mode and run the suggested commands from a shell in root mode there. I will let you know if that approach works.

    – ByteByByte
    Jan 10 at 3:22













  • While you are fixing sudo, you probably need to fix pkexec too.

    – xiota
    Jan 10 at 3:28













  • I ran the commands you listed from a root shell in recovery mode. Unfortunately, I still can't use sudo or pkexec outside of recovery mode, and I get the same error messages as I did previously. What should I do to fix pkexec? (I tried googling this but didn't find anything helpful)

    – ByteByByte
    Jan 10 at 3:54











  • probably whatever you did did too much damage, and you'll need to reinstall.

    – xiota
    Jan 10 at 4:15











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1108162%2fhow-to-solve-this-error-sudo-usr-local-bin-sudo-must-be-owned-by-uid-0-and-ha%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














must be owned by uid 0 and have the setuid bit set





  1. Check the current owner and permissions with ls -l /usr/bin/sudo. It should similar to:



    -rwsr-xr-x 1 root root 157192 2018-08-23 10:36:40 /usr/bin/sudo



  2. Run pkexec bash in a terminal to get a shell with root permissions.



  3. Fix ownership of the file:



    chown root:root /usr/bin/sudo



  4. Set the setuid bit:



    chmod u+s /usr/bin/sudo


  5. sudo should now be available for you to make further repairs.







share|improve this answer


























  • Pretty good thinking! Back when I wrote my answer I didn't even know about pkexec. I sure do now! Great answer!

    – Terrance
    Jan 9 at 14:28











  • @xiota Thank you for this very thorough response. When I checked the current owner and permissions, it was extremely similar to what you showed, -rwsr-xr-x 1 root root 149080 Jan 17 2018 /usr/bin/sudo. However, when I ran pkexec bash, I got an error message, pkexec must be setuid root. Since I wasn't able to get a shell with root permissions, I am going to boot up in recovery mode and run the suggested commands from a shell in root mode there. I will let you know if that approach works.

    – ByteByByte
    Jan 10 at 3:22













  • While you are fixing sudo, you probably need to fix pkexec too.

    – xiota
    Jan 10 at 3:28













  • I ran the commands you listed from a root shell in recovery mode. Unfortunately, I still can't use sudo or pkexec outside of recovery mode, and I get the same error messages as I did previously. What should I do to fix pkexec? (I tried googling this but didn't find anything helpful)

    – ByteByByte
    Jan 10 at 3:54











  • probably whatever you did did too much damage, and you'll need to reinstall.

    – xiota
    Jan 10 at 4:15
















1














must be owned by uid 0 and have the setuid bit set





  1. Check the current owner and permissions with ls -l /usr/bin/sudo. It should similar to:



    -rwsr-xr-x 1 root root 157192 2018-08-23 10:36:40 /usr/bin/sudo



  2. Run pkexec bash in a terminal to get a shell with root permissions.



  3. Fix ownership of the file:



    chown root:root /usr/bin/sudo



  4. Set the setuid bit:



    chmod u+s /usr/bin/sudo


  5. sudo should now be available for you to make further repairs.







share|improve this answer


























  • Pretty good thinking! Back when I wrote my answer I didn't even know about pkexec. I sure do now! Great answer!

    – Terrance
    Jan 9 at 14:28











  • @xiota Thank you for this very thorough response. When I checked the current owner and permissions, it was extremely similar to what you showed, -rwsr-xr-x 1 root root 149080 Jan 17 2018 /usr/bin/sudo. However, when I ran pkexec bash, I got an error message, pkexec must be setuid root. Since I wasn't able to get a shell with root permissions, I am going to boot up in recovery mode and run the suggested commands from a shell in root mode there. I will let you know if that approach works.

    – ByteByByte
    Jan 10 at 3:22













  • While you are fixing sudo, you probably need to fix pkexec too.

    – xiota
    Jan 10 at 3:28













  • I ran the commands you listed from a root shell in recovery mode. Unfortunately, I still can't use sudo or pkexec outside of recovery mode, and I get the same error messages as I did previously. What should I do to fix pkexec? (I tried googling this but didn't find anything helpful)

    – ByteByByte
    Jan 10 at 3:54











  • probably whatever you did did too much damage, and you'll need to reinstall.

    – xiota
    Jan 10 at 4:15














1












1








1







must be owned by uid 0 and have the setuid bit set





  1. Check the current owner and permissions with ls -l /usr/bin/sudo. It should similar to:



    -rwsr-xr-x 1 root root 157192 2018-08-23 10:36:40 /usr/bin/sudo



  2. Run pkexec bash in a terminal to get a shell with root permissions.



  3. Fix ownership of the file:



    chown root:root /usr/bin/sudo



  4. Set the setuid bit:



    chmod u+s /usr/bin/sudo


  5. sudo should now be available for you to make further repairs.







share|improve this answer















must be owned by uid 0 and have the setuid bit set





  1. Check the current owner and permissions with ls -l /usr/bin/sudo. It should similar to:



    -rwsr-xr-x 1 root root 157192 2018-08-23 10:36:40 /usr/bin/sudo



  2. Run pkexec bash in a terminal to get a shell with root permissions.



  3. Fix ownership of the file:



    chown root:root /usr/bin/sudo



  4. Set the setuid bit:



    chmod u+s /usr/bin/sudo


  5. sudo should now be available for you to make further repairs.








share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 9 at 8:36

























answered Jan 9 at 8:10









xiotaxiota

1,1621523




1,1621523













  • Pretty good thinking! Back when I wrote my answer I didn't even know about pkexec. I sure do now! Great answer!

    – Terrance
    Jan 9 at 14:28











  • @xiota Thank you for this very thorough response. When I checked the current owner and permissions, it was extremely similar to what you showed, -rwsr-xr-x 1 root root 149080 Jan 17 2018 /usr/bin/sudo. However, when I ran pkexec bash, I got an error message, pkexec must be setuid root. Since I wasn't able to get a shell with root permissions, I am going to boot up in recovery mode and run the suggested commands from a shell in root mode there. I will let you know if that approach works.

    – ByteByByte
    Jan 10 at 3:22













  • While you are fixing sudo, you probably need to fix pkexec too.

    – xiota
    Jan 10 at 3:28













  • I ran the commands you listed from a root shell in recovery mode. Unfortunately, I still can't use sudo or pkexec outside of recovery mode, and I get the same error messages as I did previously. What should I do to fix pkexec? (I tried googling this but didn't find anything helpful)

    – ByteByByte
    Jan 10 at 3:54











  • probably whatever you did did too much damage, and you'll need to reinstall.

    – xiota
    Jan 10 at 4:15



















  • Pretty good thinking! Back when I wrote my answer I didn't even know about pkexec. I sure do now! Great answer!

    – Terrance
    Jan 9 at 14:28











  • @xiota Thank you for this very thorough response. When I checked the current owner and permissions, it was extremely similar to what you showed, -rwsr-xr-x 1 root root 149080 Jan 17 2018 /usr/bin/sudo. However, when I ran pkexec bash, I got an error message, pkexec must be setuid root. Since I wasn't able to get a shell with root permissions, I am going to boot up in recovery mode and run the suggested commands from a shell in root mode there. I will let you know if that approach works.

    – ByteByByte
    Jan 10 at 3:22













  • While you are fixing sudo, you probably need to fix pkexec too.

    – xiota
    Jan 10 at 3:28













  • I ran the commands you listed from a root shell in recovery mode. Unfortunately, I still can't use sudo or pkexec outside of recovery mode, and I get the same error messages as I did previously. What should I do to fix pkexec? (I tried googling this but didn't find anything helpful)

    – ByteByByte
    Jan 10 at 3:54











  • probably whatever you did did too much damage, and you'll need to reinstall.

    – xiota
    Jan 10 at 4:15

















Pretty good thinking! Back when I wrote my answer I didn't even know about pkexec. I sure do now! Great answer!

– Terrance
Jan 9 at 14:28





Pretty good thinking! Back when I wrote my answer I didn't even know about pkexec. I sure do now! Great answer!

– Terrance
Jan 9 at 14:28













@xiota Thank you for this very thorough response. When I checked the current owner and permissions, it was extremely similar to what you showed, -rwsr-xr-x 1 root root 149080 Jan 17 2018 /usr/bin/sudo. However, when I ran pkexec bash, I got an error message, pkexec must be setuid root. Since I wasn't able to get a shell with root permissions, I am going to boot up in recovery mode and run the suggested commands from a shell in root mode there. I will let you know if that approach works.

– ByteByByte
Jan 10 at 3:22







@xiota Thank you for this very thorough response. When I checked the current owner and permissions, it was extremely similar to what you showed, -rwsr-xr-x 1 root root 149080 Jan 17 2018 /usr/bin/sudo. However, when I ran pkexec bash, I got an error message, pkexec must be setuid root. Since I wasn't able to get a shell with root permissions, I am going to boot up in recovery mode and run the suggested commands from a shell in root mode there. I will let you know if that approach works.

– ByteByByte
Jan 10 at 3:22















While you are fixing sudo, you probably need to fix pkexec too.

– xiota
Jan 10 at 3:28







While you are fixing sudo, you probably need to fix pkexec too.

– xiota
Jan 10 at 3:28















I ran the commands you listed from a root shell in recovery mode. Unfortunately, I still can't use sudo or pkexec outside of recovery mode, and I get the same error messages as I did previously. What should I do to fix pkexec? (I tried googling this but didn't find anything helpful)

– ByteByByte
Jan 10 at 3:54





I ran the commands you listed from a root shell in recovery mode. Unfortunately, I still can't use sudo or pkexec outside of recovery mode, and I get the same error messages as I did previously. What should I do to fix pkexec? (I tried googling this but didn't find anything helpful)

– ByteByByte
Jan 10 at 3:54













probably whatever you did did too much damage, and you'll need to reinstall.

– xiota
Jan 10 at 4:15





probably whatever you did did too much damage, and you'll need to reinstall.

– xiota
Jan 10 at 4:15


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1108162%2fhow-to-solve-this-error-sudo-usr-local-bin-sudo-must-be-owned-by-uid-0-and-ha%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?