1

I attempted to change shell from bash to tcsh via editing /etc/passwd file directly. Yeah, dumb move. I guess I've learned my lesson. Now I can't SSH into the remote server.

Any way to fix this?

PS. I can still connect to MySQL server via SSH tunnel. Any way to use this?

1
  • 1
    For your future reference. Please use vipw if you want to edit passwd with a text editor. It does some error checking for you.
    – Zoredache
    Oct 20, 2010 at 6:57

5 Answers 5

2

In the rather likely case of this being a VPS, check your provider for some kind of single user mode terminal. Most provide something that allows for this sort of disaster recovery.

1

Are there any other users on the box who can login through SSH? (must be in sudoers, unless you have a root password set) other than that you will need to have physical access to the box to boot into single user mode and reset the password or restore from a backup...

0

If you can connect to MySQL, I believe you can run the following to attempt to get a BASH prompt:

\! bash

I'm not sure how it would work with your shell not set correctly, but it's worth a shot. This might also vary depending on the version of MySQL you have, but it definitely works on 5.1.49 on Ubuntu. Also, maybe this would at least let you edit the file:

\! vi /etc/passwd
2
  • I think this will spawn a shell and then execute the desired command, which unfortunately wouldn't work in this case.
    – mark
    Oct 20, 2010 at 1:04
  • That gives you a shell on the local computer, not the remote one. Oct 20, 2010 at 1:10
0

This will not help you login, but the shell you specify needs to be in the /etc/shells file and installed of course. ;)

As the others have commented, you need either physical access or some kind of single user applet or have the host fix it for you.

0

vipw doesn't check to see if you gave a valid path to a shell, or whether a shell exists. What it does do is lock the file that's being edited in an attempt to prevent corruption from happening if someone else tries to edit the file at the same time.

It's possible that tcsh isn't installed, or is in a different path than bash; /usr/local/bin for example. If the OP had /bin/bash as a shell and merely changed bash to tcsh, and there's no /bin/tcsh... On my Fedora 13 laptop, I don't have tcsh at all.

Also, SSH may or may not care about /etc/shells. Traditionally that file is checked by ftp, but not ssh. On my Fedora 13 box, if I remove /bin/bash from /etc/shells, I'm still able to ssh in.

The OP's best bet is to have someone with root privs on the remote box edit /etc/passwd.

You must log in to answer this question.