When you connect to some remote machine using ssh, is there an easy way to address of the machine you connecting from ? (with some env variable, or hostname for instance)

Main use how that would be to scp/transfer file back where you connect from, without having to disconnect.

(Might be a possible duplicate, didn't realy how to well formulate the question)


As an extension of Bruce's answer, you can get only the originating IP address (instead of a string containing the IP address, the source port, and the destination port) by doing this:

echo "${SSH_CLIENT%% *}"

This works by stripping everything from the first space onwards, leaving you with only the originating IP.


If you have logged in via ssh, the environment variable SSH_CLIENT has the "from machine's" IP address in it.

If you have logged in via some other method (you should NOT be logging in via telnet), the who and w commands tell you where you came from.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.