Super User is a question and answer site for computer enthusiasts and power users. 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

Is there a way to bypass or prevent the execution of ~/.profile when logging into a remote Linux server using either ssh or putty?

share|improve this question
Why would you want to do this? Why not just edit the values in the file? (It's your profile, after all.) – Telemachus Sep 28 '09 at 19:52
This is usefull for instance if someone screwed up the .profile file and you don't have direct access to the system :) – monkey_p Sep 28 '09 at 20:14
That's exactly the situation I found myself in monkey_p – Andrew Hampton Sep 29 '09 at 18:57
up vote 21 down vote accepted

For bash:

$ ssh hostname "bash --noprofile"
share|improve this answer
You'll also need the -t option, I think. – grawity Sep 29 '09 at 13:22
ssh -t hostname "bash --noprofile" .If -t wasn't there I was getting the error "standard in must be a tty". – nitins Jun 25 '13 at 12:01

If you are looking to disable all login scripts, you can use the --noprofile flag to disable /etc/profile, ~/.profile, etc. and --norc to disable ~/.bashrc like so:

$ ssh "bash --noprofile --norc"

Keep in mind you can also launch an alternative shell if one is available. I've had to use this after messing up in chsh:

$ ssh sh

This will most likely drop you to a blank shell (no prompt) so give it an ls to make sure it is working.

share|improve this answer

If your target machine is in a bash shell:

user@host:/$ ssh hostname "bash --noprofile"

Alternatively, if there's another profile you wish to use

user@host:/$ ssh hostname "bash --noprofile; source ~/.other_profile"
share|improve this answer

Also, try using a FTP program like WinSCP to delete the mistaken login file. This will discard it, but at least you should be able to login to the default shell

share|improve this answer
or perhaps just rename it. – jezmck May 15 '13 at 14:32

As others have mentioned, running with the --noprofile flag when you initiate the connection will work, although if you're using a different shell this may or may not be an option.

One alternative would be to have the profile script detect an SSH connection itself and behave accordingly. Since SSH connections will normally set a number of environment variables, this can easily be checked. Adding something like the following lines to the start of your profile should suffice:

if [ "$SSH_CONNECTION" != "" ]; then
  echo Logging in with ssh
  echo Logging in with something that is not ssh

# rest of your profile goes here

The return will skip the rest of the script if the $SSH_CONNECTION environment variable is set, which would normally be created whenever an SSH connection is initiated. Otherwise the profile will be run like normal.

Note that this will only skip the affected profile script. All other profile scripts (e.g.: /etc/profile) would still be processed unless you modify them similarly.

share|improve this answer

You must log in to answer this question.

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