10
3
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.
One of the purposes of ProxyCommand is of course to hide (or forget about) the origin host (which may for example be not routable from the final host anyway) – Hagen von Eitzen – 2013-08-20T08:14:15.370
Can you give an example where or why do you need this information? There could be other non-obvious solutions. – Manwe – 2013-08-21T05:54:16.197
@Manwe I'll ultimately want to set up locale specific sections in things like my .bashrc. Right now all I want to do is set one of three keyboard layouts automatically in vim depending on what machine I'm working from.
– Geodesic – 2013-08-21T07:26:28.870