Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from Oct 20 '10 at 0:18

This question came from our site for professional and enthusiast programmers.

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 '10 at 6:57

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.

share|improve this answer

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

share|improve this answer

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
share|improve this answer
I think this will spawn a shell and then execute the desired command, which unfortunately wouldn't work in this case. – mark Oct 20 '10 at 1:04
That gives you a shell on the local computer, not the remote one. – toppledwagon Oct 20 '10 at 1:10

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.

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.