0

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

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

Now I can not login as root. When I enter the su command, Cannot execute /sbin/nologin: No such file or directory is displayed in console.

I have no physical access to the server. I have no users in the sudoers file.

Can you please help me to log in as root?

1
  • 1
    Is this an Ubuntu system at all?
    – guntbert
    Apr 5, 2013 at 18:52

2 Answers 2

4

If you don't have any sudoers - you are screwed up :)

I'm afraid you will need to have a physical access and a Live CD/USB to fix this problem.

2
  • In addition to @Andrejs answer, if you do have a sudoer simply sudo /bin/bash and edit the /etc/passwd back to normal. Apr 5, 2013 at 16:33
  • Sadly not an option in this case. "I have not users in sudoers file"
    – Hennes
    Apr 5, 2013 at 16:54
2

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).

2
  • Sadly none of the options has the solution in case if there are no sudoers or physical access. Apr 5, 2013 at 18:27
  • Aye. You need real physical access (even if only a local help from a datacenter which enters two or three commands), or 'remote physical' access (You really want DRACs in remote servers. Really. But that only help you when you choose the next server), or a way to recover with a reboot (e.g. via remote power and a reboot into a know safe OS). If none of those precautions are taken or you do not have those options then there is but one option left: Go over there and fix it. :(
    – Hennes
    Apr 5, 2013 at 19:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .