检测共享ssh会话

时间:2017-10-24 21:44:34

标签: linux ssh

在我的工作中,我必须ssh到不同的机器。为了让我的生活更轻松,我一直在尝试自动设置每台机器的颜色方案,这样我就可以一目了然地知道我正在做哪一个。

几乎正在工作。

的〜/ .ssh /配置:

Host some-remote-server
    Hostname some-remote-server.ac.uk
    User myusername
    IdentityFile ~/.ssh/id_rsa
    ForwardAgent yes
    ForwardX11 yes

Host some-other-remote-server
    Hostname some-other-remote-server.ac.uk
    User myusername
    IdentityFile ~/.ssh/id_rsa
    ForwardAgent yes
    ForwardX11 yes
    ProxyCommand ssh -Y some-remote-server -W %h:%p
    ControlMaster auto
    ControlPath /tmp/ssh-socket-%r@%h-%p
    ControlPersist 600

让我们假装我想要两个"一些远程服务器"和#34;某些其他远程服务器"是蓝色的我想要"我的本地服务器"变红了。

登录没问题;在"〜/ .profile"中有一些代码。它适当地设置了colorscheme。但是,退出是有问题的。

〜/ .bash_logout中:

if [[ $- == *i* ]]; then
  ORIGIN_HOST=`who am i | awk -F"[()]" '{print $2}'`
  $HOME/bin/set_the_colorscheme $ORIGIN_HOST
fi

当我从my-local-server退出ssh会话到某个其他远程服务器时,上面的脚本将$ ORIGIN_HOST标识为" some-remote-server" (我的SSH配置文件中的ControlMaster设置的b / c),因此颜色保持蓝色。

是否有检测到我正在使用ControlMaster并找到发出原始ssh命令的主机?

感谢。

0 个答案:

没有答案
相关问题