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 put "exit" in my .bashrc file. I don't have physical access to the machine so to connect to it I use ssh. I don't have root privileges. Every time I connect to the server, the connection automatically closes.

So far, I've tried:

  • Overwriting .bashrc with scp and sftp. The connection closes before I can do anything.
  • Using a few different GUI programs to access ssh (connection closes)
  • Overwriting the file with ftp. (can't use ftp)
  • From my home computer
    • $ ssh host "bash --noprofile --norc" (connection closes)
    • $ ssh host "mv .bashrc bashrc_temp" (connection closes)
    • $ ssh host "rm .bashrc" (same thing)
    • $ ssh host -t (connection closes)

Is there anything I can do to disable .bashrc or maybe overwrite the file before .bashrc is sourced?



I tried your suggestion, but no luck. The bashrc file still runs first.

Another thing I tried was logging in with another account and sudo editing the .bashrc, but I don't have sudo privileges on this account.

I guess I'll contact the admin.



I can't believe it, but this approach worked! Even though "exit" occurs within the first few lines (composed only of a few if blocks and export statements) in the .bashrc file, I still managed to Ctrl-c interrupt it successfully within twenty tries (took about 3 minutes). I removed the offending line in the .bashrc and everything is in working order again.

share|improve this question

migrated from Nov 27 '10 at 15:07

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

2 you should have (temporary) an access as a user who can overwrite your .bashrc file, or change your default shell to something else. "Ask your system Administrator" as MS says. – khachik Nov 27 '10 at 9:05
man 8 sshd says that it 9. Runs user's shell or command. as the ninth step... :-/ – khachik Nov 27 '10 at 9:17
scp will also stop working because the shell still gets opened and .bashrc gets called – Aleksandr Levchuk Nov 28 '10 at 2:51
up vote 32 down vote accepted

you can try to abort (ctrl+C) before the exit part of your .bashrc is executed.

I tried by adding the following at the top of a testuser's bashrc, it works, it's just a matter of timing. Very easy in my case:

sleep 3
echo "Too late... bye"
exit 0
share|improve this answer
+1, because it's probably the only solution that doesn't require help from the system administrator. However, a lot of luck is required to have correct timing (ssh -v host might help a bit). – JooMing Nov 27 '10 at 20:38
Actually the ctrl+C did work. Even without the sleep. I placed "exit" into my bashrc and was able to recover with a quick ctrl+C after about 4 tries. Please make some edit the answer so I can change the "-1" to "+1". – Aleksandr Levchuk Nov 28 '10 at 2:49
@Aleksandr Levchuk done – shellholic Nov 28 '10 at 2:54
Unbelievable, this works! – Dongsheng Cai Dec 1 '12 at 12:52
I very much appreciate the combination of pathetically ridiculous low-tech and brutal effectiveness here. – unixtippse Jun 11 '13 at 16:06

I managed to mess up my .bashrc file too on a new cluster I've been given trial access to. Not wanting to seem like a noob, the last thing I wanted to do was ask for help from the admins, and I couldn't get a well-timed ^+C to work.
What did work however, was to send an 'rm' command as a final argument to ssh. i.e.

ssh -tv user@host rm .bashrc

I couldn't get a 'mv' command to work (tried before without -t), so I think the -t option must have done it, but you can test that if you want. I've now recovered from the .bashrc~ file (made by vim) everything but the dodgy line in question and everything is right in the world! =D

share|improve this answer
ssh -tv user@home mv .bashrc .bashrc-old worked for me – Code Commander Jul 15 '15 at 16:10

If you can log in as a different user, try this:

su user -s /bin/sh

You'll need your password, of course.

share|improve this answer
you could try different, not sh based shell: ksh or csh – Hubert Kario Nov 27 '10 at 17:41

If I recall some bad experiences I have had like this, the ssh, scp, sftp do seem to run the initialization files.

My suggestion is to use simple FTP and then delete or rename file bad file on the FTP command line after logging in. I'm assumming that your system will allow you FTP access. In such a case, be sure to change your password (securely) when you have finished repair.

share|improve this answer
Filezilla worked perfectly for this. Just have to drop-down "Server" menu and select "Force show hidden files" setting. – Danny G Aug 31 '15 at 1:57

From man ssh (for OpenSSH_5.6p1 at least, not sure when it was added),

        Commands in this file are executed by ssh when the user logs in, just
        before the user's shell (or command) is started.  See the sshd(8) manual
        page for more information.

..which means you can create ~/.ssh/rc containing the following:

mv ~/.bashrc ~/bak.bashrc

Then when you ssh in, the problematic bashrc will be moved out the way, before your login shell is started - you can then obviously fix the bak.bashrc and move it back into place

share|improve this answer

Connect via SCP or SFTP and edit/rename/delete your .bashrc file that way. Edit - D'oh, I see you said you tried that. Oh well.

share|improve this answer

I've had the same problem, and somehow was able to solve it. I used ssh to access the system, and pressed and held Ctrl+c as soon as I logged into the system. Then, ~/.bashrc was not read, and I was able to modify it.

share|improve this answer
Exact duplicate of the most upvoted answer here – pauska Feb 18 '11 at 22:57

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.