ssh隧道链

发布于 2024-07-25 01:26:55 字数 315 浏览 2 评论 0原文

这是我尝试通过 scp 访问 server3 的场景

,但只有对服务器 1 的公共 ssh 访问权限。要 ssh 到 server3,我必须 ssh 到 server1,ssh 到 server2,然后 ssh 到 server3。

我希望的最终结果是我可以通过 WinSCP 访问 localhost:8022,它将使我能够访问 server3 的文件。

我正在尝试使用 ssh 隧道,但通过我读过的所有教程和问题,似乎没有一个适用于这种情况。

我在 Windows 上使用腻子。

任何建议都会真正有帮助。 谢谢。

Here is the scenario

I am trying to get scp access to server3, but there is only public ssh access to server 1. To ssh to server3, I have to ssh to server1, ssh to server2, then ssh to server3.

My hopeful end result would be that I could WinSCP to localhost:8022 and it will give me file access to server3.

I am trying to use ssh tunnels, but through all the tutorials and questions I have read none seem to work for this scenario.

I am using putty on Windows.

Any suggestions would be truly helpful. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

未蓝澄海的烟 2024-08-01 01:26:55

在 OpenSSH 中,当我需要隧道时我会使用此设置。 这使我可以直接输入 sftp server3,而不必担心先手动启动 server2server1 隧道。

# ~/.ssh/config

# to connect to server2, tunnel through server1
Host server2
ProxyCommand ssh server1 nc %h %p

# to connect to server3, tunnel through server2
Host server3
ProxyCommand ssh server2 nc %h %p

为了更完整,我通常使用 ssh -oCiphers=arcfour128,arcfour256,arcfour,blowfish-cbc -oControlMaster=no -oForwardX11=no -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes server1 nc %h %p 作为ProxyCommand

  • 隧道中的 ssh 连接已经加密,因此在外层使用较重的 aes/3des 是没有意义的; arcfourblowfish 速度更快。
  • 其余的 -o**** 设置出于偏执,因此即使将具有非常奇怪的设置的 Host server1 节添加到 也不会中断ssh_config

同样,您可以配置PuTTY使用代理命令plink -P %proxyport -pw %pass %user@%proxyhost nc %host %port,并在中设置代理主机名/端口/用户/密码相应的连接/代理配置窗格。 plink 和 PuTTY 套件的其余部分(pscppsftp 等)加载 PuTTY 图形配置中保存的任何内容; 希望 WinSCP 也能做到。 (我没有使用它,所以我不太熟悉它的功能。)

In OpenSSH, I use this setup when I need tunnels. This allows me to directly type sftp server3 without having to worry about manually starting the server2 and server1 tunnels first.

# ~/.ssh/config

# to connect to server2, tunnel through server1
Host server2
ProxyCommand ssh server1 nc %h %p

# to connect to server3, tunnel through server2
Host server3
ProxyCommand ssh server2 nc %h %p

To be more complete, I usually use ssh -oCiphers=arcfour128,arcfour256,arcfour,blowfish-cbc -oControlMaster=no -oForwardX11=no -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes server1 nc %h %p as the ProxyCommand.

  • The ssh connection being tunneled is already encrypted, so there's no point in using the heavier aes/3des for the outer layer; arcfour and blowfish are faster.
  • The rest of the -o**** settings are out of paranoia, so that nothing breaks even if a Host server1 stanza with really odd settings is added to ssh_config.

Similarly, you can configure PuTTY to use the proxy command plink -P %proxyport -pw %pass %user@%proxyhost nc %host %port, and set the proxy hostname/port/user/password in the Connection/Proxy configuration pane accordingly. plink and the rest of the PuTTY suite (pscp, psftp, etc.) load anything saved in PuTTY's graphical configuration; hopefully WinSCP does too. (I don't use it, so I'm not too familiar with its features.)

℡寂寞咖啡 2024-08-01 01:26:55

我想到的第一个解决方案是将一个本地端口隧道连接到每台服务器。 由于 SSH 使用端口 22,我们将使用每个 SSH 连接将本地端口隧道连接到下一个服务器的端口 22。

当您打开 PuTTY 时,您会看到 PuTTY 配置对话框。 您需要编辑的两个类别是“会话”和“连接→SSH→隧道”。

  1. 打开 PuTTY 的副本。 使用这些设置:

    • 连接到主机

      • 主机名:server1
      • 端口:22
    • 建立端口隧道

      • 本地模式
      • 源端口:15500
      • 目标:server2:22(安全 shell 端口)

        按添加之前的 PuTTY 配置窗口
        按添加后的 PuTTY 配置窗口

    现在,每次连接到本地计算机上的端口 15500 时,您的连接都会通过隧道传输到 server2 上的端口 22。

  2. 打开 PuTTY 的副本。 使用这些设置:

    • 连接到主机
      • 主机名:localhost
      • 端口:15500
    • 建立端口隧道
      • 本地模式
      • 源端口:15501
      • 目标:server3:22(安全 shell 端口)
  3. 打开 PuTTY 的副本。 使用这些设置:

    • 连接到主机
      • 主机名:localhost
      • 端口:15501
    • 建立端口隧道
      • 本地模式
      • 源端口:15502
      • 目标:server3:22(安全 shell 端口)
  4. 使用 WinSCP 连接到 localhost 在端口 15502 上。 您的连接将通过隧道进行连接,就像您直接连接到 server3 一样。

在评论中让我知道这是否适合您。 祝你好运!

The first solution that leaps to mind is to tunnel one local port to each of your servers. Since SSH uses port 22, we'll use each SSH connection to tunnel a local port to the next server's port 22.

When you open PuTTY, you're met with the PuTTY Configuration dialog. The two categories you'll need to edit are "Session" and "Connection→SSH→Tunnels".

  1. Open a copy of PuTTY. Use these settings:

    • Connect to host

      • Host name: server1
      • Port: 22
    • Tunnel a port

      • Local mode
      • Source port: 15500
      • Destination: server2:22 (the secure shell port)

        PuTTY Configuration window before pressing Add
        PuTTY Configuration window after pressing Add

    Now, every time you connect to port 15500 on your local machine, your connection is being tunneled to port 22 on server2.

  2. Open a copy of PuTTY. Use these settings:

    • Connect to host
      • Host name: localhost
      • Port: 15500
    • Tunnel a port
      • Local mode
      • Source port: 15501
      • Destination: server3:22 (the secure shell port)
  3. Open a copy of PuTTY. Use these settings:

    • Connect to host
      • Host name: localhost
      • Port: 15501
    • Tunnel a port
      • Local mode
      • Source port: 15502
      • Destination: server3:22 (the secure shell port)
  4. Use WinSCP to connect to localhost on port 15502. Your connection will be tunneled as if you're connecting to server3 directly.

Let me know in the comments whether this works for you. Good luck!

手长情犹 2024-08-01 01:26:55

此方法类似于在打开的 ssh 配置文件中使用 proxycommand 的方法。

此方法的先决条件是所有中间(代理)主机都必须使用 Pageant 进行公钥身份验证,否则您最终将得到一个闪烁的光标而没有其他结果。 要了解有关 Pageant、PuTTYgen 和公钥的更多信息,请参阅:
http://the.earth.li/~sgtatham/putty /0.62/htmldoc/Chapter8.html#pubkey
http://the.earth.li/~sgtatham/putty /0.62/htmldoc/Chapter9.html#pageant

我们有四台机器按此顺序可访问
PuttyPC-> 服务器01-> 服务器02-> server03

对于 server01,我们有一个 Putty 保存的会话:
主窗口: user1@server01 // 端口 22 // SSH
将此会话保存为 server01

对于 server02,我们有一个 Putty 保存的会话:
主窗口: user2@server02 // 端口 22 // SSH
代理配置窗口:输入 local // 代理命令 plink -load server01 -nc %host:%port
将此会话保存为 server02

对于 server03,我们有一个 Putty 保存的会话为:
主窗口: user3@pc3 // 端口 22 // SSH
代理配置面板:输入 local // 代理命令 plink -load server02 -nc %host:%port
将此会话保存为 server03

这意味着 server03 保存的会话将调用 server02 保存的会话,而 server02 保存的会话将调用 server01 会话。

This method is similar to the way you can use proxycommand in the open ssh config file.

A prerequisites for this method is that Pageant must be used with public key authentication by all intermediate (proxy) hosts otherwise you will end up with a flashing cursor and nothing else. To learn more about Pageant, PuTTYgen and public keys see:
http://the.earth.li/~sgtatham/putty/0.62/htmldoc/Chapter8.html#pubkey
http://the.earth.li/~sgtatham/putty/0.62/htmldoc/Chapter9.html#pageant

We have four machines accessible in this order
PuttyPC -> server01 -> server02 -> server03

For server01 we have a Putty saved session as:
Main Window: user1@server01 // port 22 // SSH
Save this session as server01

For server02 we have a Putty saved session as:
Main Window: user2@server02 // port 22 // SSH
Proxy config window: type local // proxy command plink -load server01 -nc %host:%port
Save this session as server02

For server03 we have a Putty saved session as:
Main window: user3@pc3 // port 22 // SSH
Proxy config panel: type local // proxy command plink -load server02 -nc %host:%port
Save this session as server03

This means that the saved session for server03 will call the saved session for server02 and server02 saved session will call the server01 session.

婴鹅 2024-08-01 01:26:55

这里很好地描述了 Perl 脚本解决方案。 也请阅读该帖子的评论。

阅读有关 SSH 代理转发 的更多信息(在 perl 脚本帖子评论中引用) 。

There is nicely described perl script solution here. Do read the comments on the posting too.

Read up more on SSH Agent Forwarding (referred in the perl script post comments).

舂唻埖巳落 2024-08-01 01:26:55

答案是从 server3 反向隧道

The answer was to reverse tunnel from server3

醉态萌生 2024-08-01 01:26:55

如果您只需要超越一台服务器,我发现直接在 WinSCP 中进行此设置会更容易。

场景:计算机->server1->server2

1:设置与server2的连接

2:点击高级->连接->隧道

3:启用SSH隧道并将主机设置为server1

If you only need to overstep one server I found it easier to do this setup i WinSCP directly.

scenario: computer->server1->server2

1: Setup the connection to server2

2: Click advanced->Connection->Tunnel

3: enable the SSH tunnel and set the host to server1

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