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

Is there a way I can log my logins on the remote machine when I SSH in to said remote machine? Though I'd only occasionally have a use for this, there are times when it'd be pretty handy (e.g. scp'ing a file back to my local machine, when the remote path is particularly long)?

The machine(s) in question are running Ubuntu.

share|improve this question
up vote 2 down vote accepted

You may find last -a useful for this. Your accesses will also be logged in /var/log/auth.log (but by IP).

share|improve this answer
You can use nslookup or host to lookup the domain name of the IP address. – Dennis Williamson Oct 31 '10 at 14:27
whitequark@hagalaz:~$ ssh dagaz
Linux dagaz 2.6.26-2-686 #1 SMP Thu Sep 16 19:35:51 UTC 2010 i686
whitequark@dagaz:~$ env | grep SSH
SSH_CLIENT= 38427 22

The host can be extracted with following bashism:

$ echo ${SSH_CLIENT%% *}

or using sed, if you like:

$ sed -e "s/ .*$//" <<<$SSH_CLIENT
share|improve this answer

Try who am i though i don't have a machine to test from. I often use this to set DISPLAY.

share|improve this answer

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.