通过命令行通过 SOCKS5 代理打开 putty ssh 连接

Open putty ssh connection over SOCKS5 proxy via command line

我尝试通过命令行打开 SOCKS5 代理上的 putty ssh 连接。

putty.exe -P port -pw password username@host -nc proxyhost:proxyport

这个命令不起作用,我认为它不正确。我尝试了这个命令的很多变体,但 putty 用户手册不包含必要的信息。

我尝试连接到我的主机 throw putty UI,它工作正常。

对于openSSH类似的命令看起来

ssh -o "ProxyCommand=nc -x proxyhost:proxyport %h %p" -p port username@host

如果我是你,我会用 Putty 创建一个 "Saved Session" 并通过命令行启动它:

putty.exe -load session_name

通过 PuTTY 界面创建 "Saved Session" 比使用命令行更容易。而且您似乎已经通过 PuTTY 界面使用它了。

尽管这是一个旧线程,但我想补充两分钱,因为我发现很难收集所有必要的信息来通过 SOCKS-5 代理建立工作 ssh 连接putty 命令行和这个线程出现在我的结果列表中。

TL;DR

目前无法(从 putty v0.74 开始)使用 puttyplink 作为 proxy-command 在命令行上。对于 windows,您必须使用类似 ncat 的替代方法,例如:

putty -p <targetport> -proxycmd "ncat.exe --proxy-type socks5 --proxy <proxyhost>:<proxyport> <targethost> <targetport>" <targethost>

详情

putty GUI 允许配置 SOCKS-5 代理,参见 putty documentation

中正确所述,BlakBat 可以使用 -load 参数通过命令行调用此配置。

命令行参数 -proxycmd 触发使用所谓的 'local' 代理连接(参见 putty documentation again):

> 3.8.3.24 -proxycmd: specify a **local** proxy command

本地代理命令是在本地计算机上发出的命令,它将处理代理连接(请参阅有关代理类型的文档)。 ncat 就是这样一个命令,它能够与 SOCKS-5 代理交互。

最后,使用plink/putty作为代理命令是很诱人的,可以避免使用多个工具。 Putty 声称 通过 -nc 参数提供 netcat 实用程序的替代方案,但是 putty documentation 指出:

If you want your local proxy command to make a secondary SSH connection to a proxy host and then tunnel the primary connection over that, you might well want the -nc command-line option in Plink.

如果您尝试使用 -nc 参数打开 SOCKS-5 连接,您的 SOCKS 服务器日志可能会显示如下内容:

sockd[1234]: info: block(1): tcp/accept ]: 1.2.3.4.4711 1.2.3.5.1080: error after reading 1 byte in 0 seconds: unknown SOCKS version 83 in client request

这表明已尝试打开与 SOCKS-5 服务器的 SSH 会话。

因此,不幸的是,据我所知,您唯一的机会是使用 putty 和 netcat-like 工具来使用 SOCKS-5 代理建立代理 SSH 连接。

简单,

putty -D 8080 <user_id>@<server_name> -pw <password>