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.

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

3 Answers 3

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
<skip>
whitequark@dagaz:~$ env | grep SSH
SSH_CLIENT=192.168.2.198 38427 22
SSH_TTY=/dev/pts/1
SSH_AUTH_SOCK=/tmp/ssh-omfqnn7365/agent.7365
SSH_CONNECTION=192.168.2.198 38427 192.168.2.10 22
whitequark@dagaz:~$

The host can be extracted with following bashism:

$ echo ${SSH_CLIENT%% *}
192.168.2.198

or using sed, if you like:

$ sed -e "s/ .*$//" <<<$SSH_CLIENT
192.168.2.198
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

 
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.