0

I am using Ubuntu 17.04.

By mistake, I have changed the ownership of sudo. So now I can't make any changes as the chown command I could use to fix it needs sudo.

If I use sudo I get

sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
Zanna
  • 70,465
  • use this :https://www.digitalocean.com/community/questions/sudo-usr-bin-sudo-must-be-owned-by-uid-0-and-have-the-setuid-bit-set – kinsley kajiva Apr 23 '19 at 09:13

3 Answers3

1

Your permission should be like following:

$ ls -l /usr/bin/sudo 
-rwsr-xr-x 1 root root 155008 May 29 15:49 /usr/bin/sudo

To do change it as default, please login with root user first and change the ownership for sudo "/usr/bin/sudo".

Eliah Kagan
  • 117,780
mAfiA
  • 11
  • 1
    This can work on Ubuntu systems where the user has already enabled root logins, but unfortunately it won't work on most Ubuntu systems because most users do not do this and logging in as root is not enabled by default in any version of Ubuntu. However, the permissions could still be changed from recovery mode. – Eliah Kagan Oct 27 '17 at 05:37
1

If you really just changed the ownership of the sudo command--that is, the file /usr/bin/sudo--then you can fix this by using pkexec instead of sudo to run chown and change the ownership back. This command does that:

pkexec chown root: /usr/bin/sudo

pkexec will prompt you for your password (as would sudo if you were able to run it).

root: means the same thing as root:root, in case you had changed the group owner as well.

If you have changed the ownership of many more files besides /usr/bin/sudo, and in particular if you have changed the ownership of all files in /usr/bin (which would also happen if you changed permissions on / or /usr but passed the -R flag to chown, specifying recursive operation), then that will not be sufficient. But based on the description you have given in the question--that you have specifically changed the ownership of /usr/bin/sudo--running that one pkexec command should be sufficient.

Eliah Kagan
  • 117,780
  • " pkexec must be setuid root "

    This is the reply i am getting....

    – Souvik Brahma Oct 27 '17 at 06:09
  • @SouvikBrahma This means you have changed the permissions or ownership of files other than /usr/bin/sudo (see my last paragraph). For reasonable advice to be given, it will be necessary for you to say more about what you actually did that resulted in the ownership of files being changed, including whatever commands you ran. (The history command may help in showing what you've run.) If you edit your question to include this information, then it should be possible to provide a more effective answer or to close the question as a duplicate of a question with an answer that will help. – Eliah Kagan Oct 27 '17 at 06:12
  • " sudo chmod +r /usr/lib/node_modules/ " && " sudo chmod +w /usr/lib/node_modules/ " are the commands that i executed – Souvik Brahma Oct 27 '17 at 06:16
  • @SouvikBrahma Please edit your question. You can paste each command you ran on its own line and indent them by 4 spaces to make them look right. (Pressing Ctrl+K , or clicking {}, will do this to text selected in the visual editor.) Though possible, it's hard to show commands unambiguously in a comment, and you haven't done so. Is that one command with " marks and && in it? Is it two commands where "&&" just means "and"? Might they be wrong by even one character? It's unclear why those commands would cause the problem you are experiencing. – Eliah Kagan Oct 27 '17 at 06:22
  • 1
    Eliah Kagan, thanks a lot, I have got my solution by logging in as root, and then using chmod ...... Thanks Again – Souvik Brahma Oct 27 '17 at 09:14
  • use this it works :https://www.digitalocean.com/community/questions/sudo-usr-bin-sudo-must-be-owned-by-uid-0-and-have-the-setuid-bit-set – kinsley kajiva Apr 23 '19 at 09:13
0

Use a Live CD to mount your system's root partition and fix the permissions from there.

fkraiem
  • 12,555
  • 4
  • 35
  • 40
  • use this https://www.digitalocean.com/community/questions/sudo-usr-bin-sudo-must-be-owned-by-uid-0-and-have-the-setuid-bit-set – kinsley kajiva Apr 23 '19 at 09:12