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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4974131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:04:08  来源:igfitidea点击:

How to create SSH tunnel using PuTTY in Windows?

windowssshputtyssh-tunnel

提问by DixieFlatline

I need to create SSH tunnel with PuTTY in Windows, that would do the same as this command in Linux:

我需要在 Windows 中使用 PuTTY 创建 SSH 隧道,这与 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 -Lswitch suggests).

我在 PuTTY 中尝试了许多选项,包括将 GUI 中的源端口设置为“2000”,将目标设置为“SomeIp:2000”。目的地设置为本地(如-L交换机建议的那样)。

I successfully login to my SSH box but port forward is not made.

我成功登录到我的 SSH 盒,但没有进行端口转发。

Is this even possible in Windows, so that all the connections made by programs that use this port (2000) will go through this tunnel?

这在 Windows 中甚至是可能的,以便使用此端口 (2000) 的程序建立的所有连接都将通过此隧道?

采纳答案by Barend

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

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

回答by Martin Prikryl

With the PuTTY suite, you can set up a tunnel either using the PuTTY itself (GUI) or using the command-line tool plink.exe.

使用 PuTTY 套件,您可以使用 PuTTY 本身 (GUI) 或使用命令行工具来设置隧道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,您使用与 OpenSSH 相同的参数ssh,除了-f,它在 Windows 中没有等效项。

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

Reference: Using the command-line connection tool Plink

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



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

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

PuTTY tunnel settings

PuTTY 隧道设置

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

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

PuTTY event log

PuTTY 事件日志

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

-N该选项翻译“不启动所有程序或命令”

PuTTY option Don't start a shell or command at all

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

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.

但是使用 GUI 客户端启用它可能没有意义,因为无论如何你都会得到一个窗口,你就不能用它做任何事情。另请参阅PuTTY Wish no-terminal-window

回答by user611775

Or you can wade through the putty GUI, which also allows this. See Connection > SSH > Tunnelson the left side with the option tree.

或者您可以通过 putty GUI 涉水,这也允许这样做。查看Connection > SSH > Tunnels左侧的选项树。

enter image description here

在此处输入图片说明

回答by Nick

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

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

  • using plink
  • using putty GUI
  • 使用 plink
  • 使用腻子 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:

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

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

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

-L 2000:localhost:2000

-L 2000:本地主机:2000

by changing the ports accordingly.

通过相应地更改端口。

回答by Ivan G.

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

“源”端口是运行 putty 的同一台机器上的端口号(例如,在浏览器中打开它:127.0.0.1:source)。“目标”是您要从本地计算机连接到的远程端口。在我意识到这一点后,它开始工作。