Can you find out the IP SSH-ing your computer?

9

If computer A SSHs computer B, can computer B find the IP of computer A? If so, how?

JShoe

Posted 2011-07-30T02:57:35.333

Reputation: 1 142

Handy when using C9.io or other services to get to EC2, and then re-restricting the network traffic rules to that IP. – Danny Staple – 2013-12-20T15:01:27.440

Answers

8

SSH connection info is also stored in the SSH_CONNECTION environmental variable.

You should be able to view this by entering echo $SSH_CONNECTION.

jmccrohan

Posted 2011-07-30T02:57:35.333

Reputation: 96

8

Yes. Just run netstat:

netstat --tcp --numeric

Look for the IP using the port 22. --numeric forces netstat to show IPs and --tcp only shows TCP connections

nmat

Posted 2011-07-30T02:57:35.333

Reputation: 1 513

For convenience netstat --tcp --numeric | grep :22 However, it will show all SSH connections to the server, not the one you are in, which I think is implied in the question. – Lefty G Balogh – 2017-04-04T06:43:28.810

Oh and how do I do that on a Mac? – JShoe – 2011-07-30T03:16:59.210

1

According to the manpage here: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/netstat.1.html you should type netstat -n. There is no tcp filtering.

– nmat – 2011-07-30T03:24:23.507

3

Yes, and here is how in Windows:

The netstat -a command shows all conections as they happen.

enter image description here

I am not a Linux guru, but it is very similar, and the actual base command is the same, I believe:

http://www.thegeekstuff.com/2010/03/netstat-command-examples/

KCotreau

Posted 2011-07-30T02:57:35.333

Reputation: 24 985

For the record you would be looking for an IP address with :22 at the end. – KCotreau – 2011-07-30T03:07:06.043

1

For SSH on a specific interface, you can also use

tcpdump -i interface port 22

This will work for linux and mac and if you have a tcpdump port for windows, it will work the same way.

MaQleod

Posted 2011-07-30T02:57:35.333

Reputation: 12 560

0

this is what you want, in a terminal:

lsof -i :ssh

it gives you the names (if available of computers sshin into your computer), if you speficically want their IP address, maybe you want to ping the name to see the IP or do an nslookup or go to http://ip2location.com ....

Ali

Posted 2011-07-30T02:57:35.333

Reputation: 1 288