用 ssh -J 通过跳板机连接内网服务器

用 ssh -J 一条命令经由堡垒机(跳板机)连到内网服务器,不用先登跳板再手动跳转。

LinuxSSH 远程连接认证隧道低风险
运行 ssh -J user@gateway.example.com user@internal-server.local,一步经跳板机连到内网机器。

01命令

命令
$ ssh -J user@gateway.example.com:2222 user@internal-server.local

02作用说明

-J 参数会让 OpenSSH 先连上跳板机,再通过它把第二条 SSH 连接转发到真正的目标机器,转发细节全自动处理。任何一台机器用了非默认端口就在地址后加 :端口,两台机器用户名不同就写成 -J gateuser@gateway,workuser@target。如果经常连同一台目标机,把 ProxyJump 写进 ~/.ssh/config 里对应主机的段落,以后直接 ssh 目标机即可。

03风险

风险低风险
!注意: 本地密钥需要同时被跳板机和目标机接受(或有意使用 agent 转发);另外跳板机能看到连接的元信息,敏感环境要选可信的跳板机。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • ssh(1) — Linux manual page (-J / ProxyJump)
    man7.org · community · 2026-09-17
    依据: Documents -J [user@]host[:port] as shorthand for ProxyJump, which connects to the target host via an intermediate jump host.
  • ssh_config(5) — ProxyJump
    OpenBSD · community · 2026-09-17
    依据: Describes the ProxyJump option and how OpenSSH forwards a TCP connection through the specified jump host.

最后验证: 2026-09-18 · 分类: 网络