Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

After logging onto a linux machine via SSH, I would like to be able to retrieve the name of the computer from which the connection was made. Ideally I am looking for some command like hostname or uname but that would retrieve the name of the client instead of the host.

This information must be accessible somewhere, since when I log on I get a message that contains the clinent name from the last login:

Last login: Thu Mar 11 18:42:01 2010 from

The reason for wanting to do this is to be able to take different action in my .login file depending on which computer I am currently connecting from.

share|improve this question
up vote 3 down vote accepted

Short answer:

who -m

For bonus marks (yes, this is filthy, someone please leave a comment as to how to do it better):

who -m | awk '{print $5;}' | sed s/\(// | sed s/\)//

share|improve this answer
That was a quick answer, thanks! – amicitas Mar 12 '10 at 9:31
@amicitas: Check again, I made it better :D Upvote if it helped you! – Alexander Burke Mar 12 '10 at 9:32
Thanks, I was about to spend the next 30 minutes trying to remember how to use awk and sed again. – amicitas Mar 12 '10 at 9:40
This is even cleaner :-): who -m | awk -F '[()]' '{print $2}' – janmoesen Mar 12 '10 at 11:46
Also note that there is a more reliable variable: SSH_CLIENT has the client IP address (and server and client port). SSH_CONNECTION adds the server IP address. – janmoesen Mar 12 '10 at 11:48

Your Answer


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.