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

1

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

sudarkoff

Posted 2011-03-18T20:56:00.413

Reputation: 13

Answers

1

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

Tim Bielawa

Posted 2011-03-18T20:56:00.413

Reputation: 990

0

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.

geekosaur

Posted 2011-03-18T20:56:00.413

Reputation: 10 195