Is there a way to bypass or prevent the execution of ~/.profile when logging into a remote Linux server using either ssh or putty?
|
|
For bash: $ ssh hostname "bash --noprofile" |
|||||
|
|
If you are looking to disable all login scripts, you can use the $ ssh 127.0.0.1 "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 $ ssh 127.0.0.1 sh This will most likely drop you to a blank shell (no prompt) so give it an |
|||
|
|
|
If your target machine is in a bash shell:
Alternatively, if there's another profile you wish to use
|
|||
|
|
|
As others have mentioned, running bash 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:
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 (ie: /etc/profile) would still be processed unless you modify them similarly. |
|||
|
|
|
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 |
||||
|
|