Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 可以写一个';无op&x27;SSH的Proxycommand?_Bash_Ssh - Fatal编程技术网

Bash 可以写一个';无op&x27;SSH的Proxycommand?

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?谢谢 您可以使用-

我最近编辑了我的SSH配置,以便Proxycommand链接到一个可执行的bash文件,我想在其中执行一些逻辑。如果满足
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