如何在 Windows 中使用 PuTTY 创建 SSH 隧道?

发布于 2024-10-17 01:56:23 字数 330 浏览 4 评论 0原文

我需要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

寒尘 2024-10-24 01:56:23

借助 PuTTY 套件,您可以使用 PuTTY 本身 (GUI) 或使用命令行工具 plink.exe 设置隧道。


对于 plink.exe,您可以使用与 OpenSSH ssh 相同的参数,但 -f 除外,它没有等效的参数在Windows中。

plink.exe -N -L 2000:SomeIp:2000 myusername@myLinuxBox

参考:使用命令行连接工具Plink


PuTTY,-L 2000:SomeIp:2000 转换为:

PuTTY 隧道设置

所以这实际上是您声称已经尝试过的。如果您有任何问题,请使用 PuTTY 事件日志进行调查:

PuTTY 事件日志

-N 转换为选项“根本不启动 shell 或命令”< /em>。

PuTTY 选项 Don根本不启动 shell 或命令

但是对于 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 OpenSSH ssh, except for the -f, which does not have an equivalent in Windows.

plink.exe -N -L 2000:SomeIp:2000 myusername@myLinuxBox

Reference: Using the command-line connection tool Plink


With the PuTTY, the -L 2000:SomeIp:2000 translates to:

PuTTY tunnel settings

So it's actually, what you claim to have tried. If you have any problems, use the PuTTY event log to investigate:

PuTTY event log

The -N translates to the option "Don't start a shell or command at all".

PuTTY 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.

寄人书 2024-10-24 01:56:23

您可能想使用 plink.exe 而不是 GUI 客户端。命令行语法与 iirc 兼容。

You probably want to use plink.exe instead of the GUI client. The command line syntax is compatible iirc.

摇划花蜜的午后 2024-10-24 01:56:23

或者你可以费力地浏览 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.

enter image description here

无法回应 2024-10-24 01:56:23

上面的答案提到了解决问题的两种不同方法:

  • plink
  • 使用putty GUI 使用

我没有 plink,并且无法下载 plink.exe 文件(它是一个受到密切监控的受限环境),因此使用了不同的脚本方式使用一行脚本的解决方案:

start putty -ssh myusername@myLinuxBox -pw my_pw -L 2000:localhost:2000

将其存储在批处理文件中(文件扩展名“.bat”,例如“tunnel.bat”)。因此,每次双击此文件时,都会运行该命令,并且 putty 会创建 ssh 隧道。如果您想要更多隧道,只需重复此部分

-L 2000:本地主机:2000

通过相应地更改端口。

The answers above mention two different ways of resolving the problem:

  • using plink
  • using putty GUI

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:

start putty -ssh myusername@myLinuxBox -pw my_pw -L 2000:localhost:2000

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

-L 2000:localhost:2000

by changing the ports accordingly.

箹锭⒈辈孓 2024-10-24 01:56:23

“源”端口是运行 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文