1

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?

Noam M
  • 451
Sild
  • 325
  • Can you log in as a regular user, and do you know the root user's password? – John Feb 26 '16 at 19:48
  • 1
    ssh -t thatserver /bin/bash might be one thing to try – thrig Feb 26 '16 at 19:49
  • Nevermind, you answered my question already. Do you have physical access to the server? – John Feb 26 '16 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 – Ivan Temchenko Feb 26 '16 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 Feb 26 '16 at 19:57
  • hmm, why it is privat key not publick? like .ssh/id_rsa.pub? what you got on running ssh root@host? – Ivan Temchenko Feb 26 '16 at 20:06
  • Replying to your update: you can't. You've configured the root account in a way that forbids logging in, so you can't log in as root. You'll need to use a local console. If it's a VPS, there's usually an option to do this somewhere in the admin interface. – Gilles 'SO- stop being evil' Feb 26 '16 at 23:07

2 Answers2

3

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.

vpathak
  • 101