flybywire flybywire - 5 months ago 20
Linux Question

Find the IP address of the client in an SSH session

I have a script that is to be run by a person that logs in to the server with SSH.

Is there a way to find out automatically what IP address the user is connecting from?

Of course, I could ask the user (it is a tool for programmers, so no problem with that), but it would be cooler if I just found out.


Check if there is an environment variable called:




(or any other environment variables) which gets set when the user logs in. Then process it using the user login script.

Extract the IP:

$ echo $SSH_CLIENT | awk '{ print $1}'
$ echo $SSH_CONNECTION | awk '{print $1}'