Bash 可以写一个';无op&x27;SSH的Proxycommand?
我最近编辑了我的SSH配置,以便Proxycommand链接到一个可执行的bash文件,我想在其中执行一些逻辑。如果满足Bash 可以写一个';无op&x27;SSH的Proxycommand?,bash,ssh,Bash,Ssh,我最近编辑了我的SSH配置,以便Proxycommand链接到一个可执行的bash文件,我想在其中执行一些逻辑。如果满足condition1,则我要执行某个Proxycommand。否则,我想要一个“无操作”;基本上我不想在这种情况下代理 我的SSH配置如下所示: Host * ProxyCommand <link_to_bashfile> %h %p 当bash文件中不满足condition1时,是否有一种方法可以模拟ProxyCommand none?谢谢 您可以使用-
condition1
,则我要执行某个Proxycommand。否则,我想要一个“无操作”;基本上我不想在这种情况下代理
我的SSH配置如下所示:
Host *
ProxyCommand <link_to_bashfile> %h %p
当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
端口=$2
如果;然后
不管实际命令是连接什么
其他的
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
host=$1
端口=$2
如果;然后
不管实际命令是连接什么
其他的
执行官nc$1$2
fi
Hm不幸的是,这对我不起作用;它似乎是作为代理命令执行ssh-oproxycommand=none-p“$port”“$host”
,而不是实际的命令。
host=$1
port=$2
if <condition>; then
whatever the actual command is to connect
else
exec nc $1 $2
fi