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

link|improve this question
feedback

2 Answers

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
else
    // code when remote login
fi
link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.