sudo: unknown user: root - please help!

November 25, 2014 15.5k views

I was using terminal, and vim, to edit my /etc/passwd file and got a ‘broken pipe’ message in the window. I have CentOS

When I logged back onto the server I tried to access the file again using sudo.

I got the following:
sudo: unknown user: root
sudo: unable to initialize policy plugin

I can open the file without sudo, and notice there are a couple of lines that were at beginning of the list that have disappeared - Luckily I’ve been keeping a 'diary’ of what I’ve been doing over the past couple of months so have a print-out of the contents of passwd.

The missing lines are:
root:x:0:0:root:/root:/bin/bashing
bin:x:1:1:bin:/bin:/sbin/nologin:

I’m able to copy the missing lines back but the file won’t save.

At the bottom of the window I see:
“/etc/passwd” [readonly] 29L, 1454C

When I hit 'ESC :wq’ I see:
E45: 'readonly’ option is set (add ! to override)

I’ve tried all manner of ways including ’:w !sudo tee %’ to try to get this file to save but to no avail.

I also discovered another warning that momentarily displayed then disappeared. I managed to get a screen shot of it.

E325: ATTENTION
Found a swap file by the name “var/tmp/passwd.swp”

While opening file “/etc/passwd”

(1) Another program may be editing the same file.

(2) An edit session for this file crashed.
If this is the case, use “:recover” or “vim -r /etc/passwd”
to recover the changes (see “:help recovery”).
If you did this already, delete the swap file “/var/tmp/passwd.swp”
to avoid this message.

Can anyone give me any suggestions please? I’ve spent all day trying to figure it out but I’m fairly new to all this.

1 comment
  • Why do you edit passwd file? there are commands to add/modify/delete users, that is very dangerous as you now can see.

    Are you login as root or as a different user?, is you are login with another user the su command works?

    If you can login as root via ssh you should not need to “sudo vim … ”, if you can’t access as root at all, then you have a really big problem. There is any other root like user in your droplet, one you granted root like access to?

1 Answer

Hi, and thank you for answering.

I followed a tutorial to set up the server and I think I did set up a new user with root privileges. I also changed the SSH default port and disabled root login.

I log on to the server like so - newusername@123.456.789. However I’ve always needed to use sudo to make changes so I assume that I didn’t set up the new user privileges correctly.

I just tried: /usr/sbin/visudo

I get this message: visudo: /etc/sudoers: Permission denied

I think I have a really big problem, like you say. What is the solution if I can’t access root?

Have another answer? Share your knowledge.