I connect to a number of machines constantly, from different physical locations (and thus different physical machines). Most of this is done though ssh, sometimes a gateway machine or two is required (which I invoke via ProxyCommand
in ~/.ssh/config
). I'd like to know if there's a method to identify the IP or hostname of the machine that calls the initial connection (ie the machine I'm working on) at the remote end?
- I don't want to send environment variables as some machines I don't have root to set
PermitUserEnvironment
. - The
$SSH_CLIENT
environment variable is useful for direct connections, but only lists the most recent gateway.
My current idea for a solution is to grab $SSH_CLIENT
, ssh to it, find that machine's $SSH_CLIENT
value and repeat until it doesn't exist; then grab the hostname and pull it back somehow.
Seems like a bit of a hack job though; does anyone have a better method?
I'm working in a bash shell mostly, but I'm also happy for any suggestions that don't use it too.