When logging in via SSH, I'd like to know, during the execution of .bashrc
, the name of the host that is connecting.
Ubuntu Server shows the prompt:
Last login: Fri Feb 14 11:34:55 2014 from somehost.local
...so this information is available somewhere.
How can I access it?
If you type:
You'll see information about the logged in users. Amongst other things, you can see the host they're logged from. For instance, right now my laptop returns this:
Where helena.local is the computer from which I'm connected trough ssh.
ssh
sets the environment variable$SSH_CONNECTION
to contain client IP address, client port number, server IP address, and server port number seperated by spaces.You can use
to get the client's IP address. To get the DNS name use something like
host
ordig -x
: