Why can't I sudo.. unknown user root

8:25 PM

Recently I came across an issue while trying to edit a file using sudo as root.
sudo reported that the user 'root' was unknown.
sudo vi /etc/root-owned-file
sudo: unknown user: root

A quick check revealed that for some reason a previous person had edited the /etc/passwd file and changed the 'root' owner to 'oot'.
root:x:0:0:root:/root:bin/bash
Was changed to
oot:x:0:0:root:/root:/bin/bash
So the root user did not exist on the host.  This could have proven catastrophic as nothing could be edited via sudo.  
You can't login as the user 'oot' with the root passwd because there is no user 'oot' in /etc/shadow

HOW TO FIX:
You can use sudo to access files as a specific user by UID.  in this case UID 0 for root.
to fix the /etc/passwd file simply use sudo and edit /etc/passwd as the UID 0

sudo -u \#0 vi /etc/passwd  
you must 'escape' the pound sign in sudo with a \ before the UID of 0
This will allow you to edit /etc/passwd as UID 0 and correct the mistakes in /etc/passwd

You Might Also Like

5 comments

  1. Hey mahn thank you so much, you saved my time and also made me stop from taking very lengthy and time consuming steps, u really rock man!! I am so relieved!!

    ReplyDelete
  2. Thanks man, this tip saved our day.

    ReplyDelete

Contact Form

Name

Email *

Message *

Translate

Wikipedia

Search results