How can I find / record the IP of a machine I SSH'd in from on, from the remote machine?

2

1

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.

Squidly

Posted 2010-10-31T00:02:00.030

Reputation: 490

Answers

2

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

Paused until further notice.

Posted 2010-10-31T00:02:00.030

Reputation: 86 075

You can use nslookup or host to lookup the domain name of the IP address. – Paused until further notice. – 2010-10-31T14:27:53.523

1

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

whitequark

Posted 2010-10-31T00:02:00.030

Reputation: 14 146

0

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

Rich Homolka

Posted 2010-10-31T00:02:00.030

Reputation: 27 121