4

I have change default root shell to wrong path. Now the first line of /etc/passwd is look like the following string:

root:x:0:0:root:/root:/usr/bin/bash

Then I logout from server and now cannot log in by root.

There is no other user on server.

I know, here is much stupid mistakes, but how I can fix it?

Access to server is available only by ssh.

UPDATE

The mission is impossible. I found a way to execute any command as www-data user. How can I change /etc/passwd as non-sudo user?

7
  • Can you log in as a regular user, and do you know the root user's password?
    – John
    Commented Feb 26, 2016 at 19:48
  • 1
    ssh -t thatserver /bin/bash might be one thing to try
    – thrig
    Commented Feb 26, 2016 at 19:49
  • Nevermind, you answered my question already. Do you have physical access to the server?
    – John
    Commented Feb 26, 2016 at 19:49
  • in that case only hope is on .ssh/authorized_keys but if you never put your key there - hope is dead and you need physicall access or iLO/other console Commented Feb 26, 2016 at 19:55
  • @IvanTemchenko I have a id_rsa to acces by key. But now when I use ssh root@host -i ~/.ssh/id_rsa the server ask me about password.
    – Sild
    Commented Feb 26, 2016 at 19:57

2 Answers 2

4

There is no way to login with ssh and a invalid shell. Setting a non-valid shell is also the standard way to use some ssh services without allowing users to login (see e.g. git). So if it where an alternate way, the security of many servers is in danger.

Likewise, having access to a non-sudoer account won't help you either. You've set the root account to a configuration that says “login not allowed”. So you aren't allowed to log in.

You need to reboot with custom kernel parameters or some local console.

0

try to run the shell command explicitly

ssh <hostname> /bin/bash 

otherwise try to craft a command to fix the etc passwd file. i beleive shell can run explicit commands and run shell is perhaps only a default. also check ssh options you may have to choose some to get it going.

You must log in to answer this question.

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