Lost root access possibility /sbin/nologin
5,478
You have a few options to recover from this:
- 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).
- 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).
- 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.
- Start the server with in single user mode. (e.g in GRUB add
single
or1
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). - 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).
- If you have a second OS (or a rescue install) on that server, then boot that and edit the files.
Regardless of what you do: Never log out when you make such changes.
Test them first (e.g. start a second connection).
Author by
Baltazor
Updated on September 18, 2022Comments
-
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 about 11 yearsThe only way to recover from such an accident is to boot in rescue mode (physical presence required).
-
ganesh about 11 yearsSame question as askubuntu.com/questions/278252/…
-
jnovack about 11 yearsI'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 about 11 yearsIt does not work. I getting the same result
Cannot execute /sbin/nologin: No such file or directory
-
Joshua over 9 yearsWhich is held up by the manual. su -s doesn't work unless you are already root or the shell is listed in /etc/shells