我最近编辑了SSH配置,以便Proxycommand链接到一个可执行的bash文件,我想在其中执行一些逻辑。如果满足condition1
,那么我想执行某个代理命令。否则,我想要一个"禁止操作";基本上我不想在这种情况下代理。
我的SSH配置看起来像:
Host *
ProxyCommand <link_to_bashfile> %h %p
然而,如果我只是不在bash文件中做任何事情,我会得到以下错误:
ssh_exchange_identification: Connection closed by remote host
当bash文件中不满足condition1
时,有没有一种方法可以本质上模拟ProxyCommand none
?谢谢
您可以使用-o
选项来覆盖配置文件中的ProxyCommand
指令,这样您就可以运行ssh
,而不会陷入代理命令的无休止循环。也就是说,在您的bash
文件中,
host=$1
port=$2
if <condition>; then
whatever the actual command is to connect
else
ssh -o ProxyCommand=none -p "$port" "$host"
fi
证明以下代码有效:
host=$1
port=$2
if <condition>; then
whatever the actual command is to connect
else
exec nc $1 $2
fi