gpt4 book ai didi

bash - 是否可以为 SSH 编写 'no-op' 代理命令?

转载 作者:行者123 更新时间:2023-11-29 09:13:53 25 4
gpt4 key购买 nike

我最近编辑了我的 SSH 配置,以便 Proxycommand 链接到一个可执行的 bash 文件,我想在其中执行一些逻辑。如果满足 condition1,那么我想执行某个 Proxycommand。否则,我想要一个“无操作”;在这种情况下,本质上我不想代理。

我的 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

关于bash - 是否可以为 SSH 编写 'no-op' 代理命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33658618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com