Windows SSH ProxyCommand /usr/bin/bash: 第 0 行: exec: nc: 在 git bash 上找不到

Sap*_*aik 2 windows ssh proxy netcat jumphost

我尝试通过 Windows Git Bash 上的中间跳转主机 SSH 到服务器,但出现以下错误。

/usr/bin/bash: 第 0 行: exec: nc: 未找到

$ ssh -vnNT -L 2555:destination-server.com ubuntu@x.amazonaws.com -o "ProxyCommand=nc -X 5 -x proxy.abc.com:4850 %h %p"

OpenSSH_8.8p1, OpenSSL 1.1.1l  24 Aug 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Executing proxy command: exec nc -X 5 -x proxy.abc.com:4850 x.amazonaws.com 22
debug1: Local version string SSH-2.0-OpenSSH_8.8
/usr/bin/bash: line 0: exec: nc: not found *********************************** => ERROR LINE
kex_exchange_identification: Connection closed by remote host
Connection closed by UNKNOWN port 65535
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个错误?

Sap*_*aik 6

原因是 Windows 版的 Git Bash 没有nc (netcat)命令。

作为解决方法,请替换:

nc -X 5 -x proxy.abc.com:4850 %h %p
Run Code Online (Sandbox Code Playgroud)

connect -S proxy.abc.com:4850 %h %p
Run Code Online (Sandbox Code Playgroud)

所以最终的命令是:

ssh -vnNT -L 2555:destination-server.com ubuntu@x.amazonaws.com -o "ProxyCommand=connect -S proxy.abc.com:4850 %h %p"
Run Code Online (Sandbox Code Playgroud)

即使您nc从 ssh 配置文件中使用,您也可以替换nc -X 5 -xconnect -S,并且它应该可以工作。

例子:

代替

代替

工作命令