Lost root access possibility /sbin/nologin

5,478

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:
5,478
Baltazor
Author by

Baltazor

Updated on September 18, 2022

Comments

  • Baltazor
    Baltazor over 1 year

    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?

    • vonbrand
      vonbrand about 11 years
      The only way to recover from such an accident is to boot in rescue mode (physical presence required).
    • ganesh
      ganesh about 11 years
    • jnovack
      jnovack about 11 years
      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?
  • Baltazor
    Baltazor about 11 years
    It does not work. I getting the same result Cannot execute /sbin/nologin: No such file or directory
  • Joshua
    Joshua over 9 years
    Which is held up by the manual. su -s doesn't work unless you are already root or the shell is listed in /etc/shells