如何在 Windows 中使用 PuTTY 创建 SSH 隧道?
我需要在 Windows 中使用 PuTTY 创建 SSH 隧道,这与 Linux 中的此命令相同:
ssh -fN -L 2000:SomeIp:2000 myusername@myLinuxBox
我在 PuTTY 中尝试了许多选项,包括将 GUI 中的源端口设置为“2000”,将目标端口设置为“SomeIp:2000”。目标设置为本地(如 -L
开关所示)。
我成功登录到我的 SSH 盒子,但未进行端口转发。
这在 Windows 中是否可能,以便使用此端口 (2000) 的程序建立的所有连接都将通过此隧道?
I need to create SSH tunnel with PuTTY in Windows, that would do the same as this command in Linux:
ssh -fN -L 2000:SomeIp:2000 myusername@myLinuxBox
I tried many options in PuTTY, including setting source port in GUI to "2000" and destination to "SomeIp:2000". Destination is set to local (as the -L
switch suggests).
I successfully login to my SSH box but port forward is not made.
Is this even possible in Windows, so that all the connections made by programs that use this port (2000) will go through this tunnel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
借助 PuTTY 套件,您可以使用 PuTTY 本身 (GUI) 或使用命令行工具
plink.exe
设置隧道。对于
plink.exe
,您可以使用与 OpenSSHssh
相同的参数,但-f
除外,它没有等效的参数在Windows中。参考:使用命令行连接工具Plink
PuTTY,
-L 2000:SomeIp:2000
转换为:所以这实际上是您声称已经尝试过的。如果您有任何问题,请使用 PuTTY 事件日志进行调查:
-N
转换为选项“根本不启动 shell 或命令”< /em>。但是对于 GUI 客户端来说启用它可能没有意义,因为无论如何你都会得到一个窗口,但你无法用它做任何事情。另请参阅 PuTTY 希望 no-terminal-window .
如果您要使用隧道通过 PuTTY 连接到另一台服务器,您实际上可以使用
plink
将隧道设置为会话设置的一部分作为代理,请参阅:相当于 OpenSSH ProxyCommand 的 PuTTY 配置。With the PuTTY suite, you can set up a tunnel either using the PuTTY itself (GUI) or using the command-line tool
plink.exe
.With the
plink.exe
, you use the same arguments as with the OpenSSHssh
, except for the-f
, which does not have an equivalent in Windows.Reference: Using the command-line connection tool Plink
With the PuTTY, the
-L 2000:SomeIp:2000
translates to:So it's actually, what you claim to have tried. If you have any problems, use the PuTTY event log to investigate:
The
-N
translates to the option "Don't start a shell or command at all".But it probably does not make sense with a GUI client to enable it, as you get a window anyway, you just cannot do anything with it. See also the PuTTY wish no-terminal-window.
If you are going to use the tunnel to connect with PuTTY to another server, you can actually set up the tunnel as a part of the session settings with use of
plink
as a proxy, see: PuTTY configuration equivalent to OpenSSH ProxyCommand.您可能想使用
plink.exe
而不是 GUI 客户端。命令行语法与 iirc 兼容。You probably want to use
plink.exe
instead of the GUI client. The command line syntax is compatible iirc.或者你可以费力地浏览 putty GUI,它也允许这样做。请参阅
连接> SSH>左侧带有选项树的隧道
。Or you can wade through the putty GUI, which also allows this. See
Connection > SSH > Tunnels
on the left side with the option tree.上面的答案提到了解决问题的两种不同方法:
我没有 plink,并且无法下载 plink.exe 文件(它是一个受到密切监控的受限环境),因此使用了不同的脚本方式使用一行脚本的解决方案:
将其存储在批处理文件中(文件扩展名“.bat”,例如“tunnel.bat”)。因此,每次双击此文件时,都会运行该命令,并且 putty 会创建 ssh 隧道。如果您想要更多隧道,只需重复此部分
通过相应地更改端口。
The answers above mention two different ways of resolving the problem:
I don't have plink and I can't download the plink.exe file (it is a closely monitored restricted environment) so used a different way to script the solution with a one-line script:
Store this in a batch file (file extension ".bat", e.g. "tunnel.bat"). So every time you double-click on this file the command is run and putty creates the ssh tunnel. If you want more tunnels just repeat this part
by changing the ports accordingly.
“源”端口是运行 putty 的同一台计算机上的端口号(例如,在浏览器中打开此端口:127.0.0.1:source)。 “目标”是您想要从本地计算机连接到的远程端口。当我意识到这一点后,它就开始起作用了。
"Source" port is a port number on the same machine from which you are running putty (eg. open this in your browser: 127.0.0.1:source). "Destination" is your remote port that you want to connect to from your local machine. It started to work after I realized this.