大网数据广告活动
服务器运维问答

SSH to Remote host via another host

· 52CE 我爱测

I am trying to ssh to remote Host B, but network access control governs I am only able to do this via Host A. How would I go about doing that? Have tried creating a tunnel to Host A ssh -f -N -D 2222 user@hostA Then when creating…

问题原文

原帖链接 · 0rangutang · CC BY-SA 3.0

I am trying to ssh to remote Host B, but network access control governs I am only able to do this via Host A. How would I go about doing that?

Have tried creating a tunnel to Host A ssh -f -N -D 2222 user@hostA

Then when creating new ssh connections from Local specifying tunnel port to tunnel those connections, but cant get this working.. ssh -L 2222:hostB:22 hostA

Hosts involved: Local Host A (local intranet) Host B (internet)

Flow of traffic: Local > HostA > HostB

Any pointers would be super hand.. thanks in advance!

已采纳解答

原帖链接 · EEAA · CC BY-SA 3.0

Your thought of using a dynamic port forward for this will never work. Think through it logically - you need to open a local port that forwards from your local machine, through hostA, to port 22 on hostB. There are a couple of ways you can achieve this. First, the inelegant, manual way:

First, set up the tunnel:

$ ssh -L2222:hostB:22 user@hostA

Then, connect to hostB:

$ ssh -p 2222 user@localhost

The preferred option is to use the ssh client's ProxyCommand directive, which can automate this for you. Add something like this to your ~/.ssh/config:

host hostB
  Hostname hostB
  ProxyCommand ssh user@hostA nc %h %p 2> /dev/null

After doing this, you can do this:

$ ssh hostB

...and the ssh client will take care of everything for you.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-04-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。