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

What's the most reliable way to distinguish local from remote logins in .bashrc?

share|improve this question
up vote 1 down vote accepted

Check out the env command time. I find that when I ssh into a remote host that a variable called $SSH_CLIENT is set and it's value is the IP address from which I am connecting.

You could check to see if that variable is null or not.

if [ -z "$SSH_CLIENT" ]; then
    // code when local login
    // code when remote login
share|improve this answer

If you use ssh (as you really should :) you can look for environment variables starting with $SSH_. Another way is who -u am i, which will show a hostname for remote logins.

share|improve this answer

You must log in to answer this question.

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