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

SSH LocalForward Through Middle Machine

· 52CE 我爱测

My setup looks like this: +--------+ +----------+ +-----------+ | Laptop | <---> | Middle | <--> | Server | +--------+ +----------+ +-----------+ And the server is running a web server on TCP:127.0.0.1:8081. All the machines are …

问题原文

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

My setup looks like this:

 +--------+       +----------+      +-----------+
 | Laptop | <---> |  Middle  | <--> |   Server  |
 +--------+       +----------+      +-----------+

And the server is running a web server on TCP:127.0.0.1:8081. All the machines are running SSH and I have credentials to everything.

Before there was the box in the middle, I used to have my SSH config that read:

Host server
    Hostname server.internal.tld
    User ubuntu
    IdentityFile ~/.ssh/some_key.pem
    Port 20022
    LocalForward 8081 localhost:8081
    ServerAliveInterval 60
    KeepAlive yes
    ServerAliveCountMax 1

This let me hit the page in my browser by browsing to localhost:8081.

Is there a line that I can add to my SSH config to get the same result now that there's a machine in the middle that I can proxy SSH through? Is this somehow what ProxyCommand is used for? Will the LocalForward line still work with ProxyCommand?

已采纳解答

原帖链接 · Gaurav Pundir · CC BY-SA 3.0

First Check if port 8081 of your web server is accessible from the middle server. If yes then you just have to use ip address of the server instead of localhost in LocalForward configuration. If no add following line in ssh config file

ProxyCommand ssh user_name@middle_server_ip  nc %h %p

LocalForward will work with ProxyCommand.

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

资料来源与适用范围

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

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

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