Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers 2

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
share|improve this answer
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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