bashrc and openssh

Just thought I’d document this for web-posterity…

Some of our systems rely on a large number of environment variables that get loaded via .profile or .bashrc, but most importantly the PATH variable.

Under Ubuntu and Fedora 9+ this stopped working when using “ssh <host> <command>”.

After much googling and head scratching, I finally found the cause.

Our bashrc files all had something like this near the start:

if [ -z "$PS1" ] ; then
  return   # or exit or something

Using OpenSSH’s ssh in command mode, e.g. ssh dev-strat stophost, results in a non-interactive login, for which “PS1” is not set.

So if you’re having a hard time getting your ssh commands to load their environment… Check for that.


The whole frigging thing about which dot files bash reads under different circumstances on different systems has stumped me for years. I’ve just given up distinguishing between .profile, .bashrc and .bash_profile or whatever and they all just source one master file…

Modern bash actually has this stuff at the top of man pages :) So it’s fairly clear now.

Then again, you might want to start looking at ‘dash’, which is a streamlined, optimized bash. It actually makes a fair amount of difference if you’re using lots of shell scripts without sourceing them. I’ve seen a 5x improvement in speed with some tool chains.

Leave a Reply

Name and email address are required. Your email address will not be published.

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <pre> <q cite=""> <s> <strike> <strong> 

%d bloggers like this: