Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I accidentally edited the file /etc/passwd on my server in the following way:

root:x:0:0:root:/root:/sbin/nologin

Now I cannot login as root. When I enter the su command, the following is displayed in the console:

Cannot execute /sbin/nologin: No such file or directory

I have no physical access to server, and my user isn't in the sudoers file.

I am running Ubuntu Server Linux 2.6.24-23-server

How do I regain access to the root user?

share|improve this question
2  
The only way to recover from such an accident is to boot in rescue mode (physical presence required). –  vonbrand Apr 5 '13 at 16:10
    
Same question as askubuntu.com/questions/278252/… –  Hennes Apr 5 '13 at 16:56
    
I'm sorry, could you possibly detail the exact circumstances which lead to this "accidental edit"? Was it a bad sed command? Solar flares? How was this not intentional? –  jnovack Apr 5 '13 at 17:36

3 Answers 3

You have a few options to recover from this:

  1. Log in with another user with sufficient rights to correct this. This obviously requires a second user with sufficient rights, but that is not that uncommon if the server has multiple admins. (Each with their username and admin account).
  2. Boot from another OS (e.g. a live CD or pen drive. mount the disk and correct the shell for root. (Trivial to do if you have physical access, but you wrote that this is not the case).
  3. Boot from another OS (e.g. a live CD or pen drive. mount the disk and correct the shell for root while accessing the console remotely via DRAC, ILO, or similar. The latter is common enough for servers and you can even point to a local ISO file to act as a fake CD.
  4. Start the server with in single user mode. (e.g in GRUB add single or 1 to the kernel parameters. This will drop you into a shell. Then ask someone local to change the shell for you. (or in case of DRAC/ILO change it yourself).
  5. If you have a user with the right to shutdown the server,but no to edit /etc/passwd. shut down the server to runlevel 1. That will drop the server to single user mode and you can edit the setting from the console (once again needing HP's ILO, Dell DRAC or similar).
  6. If you have a second OS (or a rescue install) on that server, then boot that and edit the files.

Example picture of a console seen via DRAC

Regardless of what you do: Never log out when you make such changes.
Test them first (e.g. start a second connection).

share|improve this answer

Boot the system from a Live CD in rescue mode, from which you can mount the filesystem and edit the /etc/passwd file. You will need physical access to the server unless you have a remote KVM or a product like HP's iLO.

OR,

You can do it from sudo if you have other users.

OR, you can check the other sites you spammed with your question:

share|improve this answer

I may be missing something, but this seems very very fixable, very easily.

If you can do su, you know you can do su -s /bin/bash, right?

share|improve this answer
    
It does not work. I getting the same result Cannot execute /sbin/nologin: No such file or directory –  Baltazor Apr 6 '13 at 11:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.