The Computer Oracle

Bypass ~/.profile on remote login to a linux server

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: The World Wide Mind

--

Chapters
00:00 Bypass ~/.Profile On Remote Login To A Linux Server
00:17 Accepted Answer Score 31
00:25 Answer 2 Score 5
00:42 Answer 3 Score 15
01:11 Answer 4 Score 2
02:04 Thank you

--

Full question
https://superuser.com/questions/48147/by...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #ssh #putty #profile

#avk47



ACCEPTED ANSWER

Score 31


For bash:

$ ssh hostname "bash --noprofile"



ANSWER 2

Score 15


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 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 chsh:

$ ssh 127.0.0.1 sh

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




ANSWER 3

Score 5


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"



ANSWER 4

Score 2


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
  return
else
  echo Logging in with something that is not ssh
fi

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