Id我正确理解,您是直接从源计算机通过proxycommand
跃点连接到目的地的。因此,这里有三个技巧供您参考(在对使用情况发表评论后再添加了三个技巧)。首先)使用远程端口转发,使您可以通过以下方式回到原始计算机-R remotemachineport:dstonlocalnet:dstportonlocalnet
ssh -R 2222:localhost:22 user@target
# on "target" you can now do this to get back to origin host
ssh user2@localhost -p 2222
第二)AcceptEnv LC_*
对目标的虐待。这不是很好,但是即使没有AcceptUserEnviconment时也允许LOCALE变量很普遍。现在,您可以执行以下操作:
export LC_SOURCEHOST=my.ip.addr.or:something
ssh user@target
# on tathet:
echo $LC_SOURCEHOST
第三,使用ssh远程转发来识别主机或主机类型。
# Here is an example what you can use on target machine.
# This will modify your PS1 variable (prompt) based on source host (port forwarding)
# Add this to .bash_profile
function checkHost {
RET=""
## loop over test port numbers 17891-17895 in my example
for x in $(seq 1 5); do
# if netstat is not available test port some other way like with nc or something
## && RET= will set RET = 1-5
/bin/netstat -lnt|/bin/grep -q 127.0.0.1:1789$x && RET=$x;
done
# return RET
# please note that if you have multiple open connections with different port numbers
# this method cannot not distinguish between them
echo $RET
}
# get 1-5 number from function above
VAL=$(checkHost)
# do something like set PS1 var or map vim file or something
export PS1='\[\033k\033\\\]\u@\h: \w\$ '$VAL
现在连接端口转发:
### this will still enable ssh forwarding back. Change 22 to something else like
### 24 to disable it (if nothing is listening on your source machines 24 port)
ssh -R 17891:localhost:22 user@target