跳转服务器的 SSH 和身份文件

Mik*_*dez 10 ssh bash

my-server我正在尝试通过跳转服务器登录jump.example.com

我可以成功登录跳转服务器,无需密码请求:

ssh -i .ssh/id_rsa user@jump.example.com
Run Code Online (Sandbox Code Playgroud)

但如果我使用

ssh -i .ssh/id_rsa -o ProxyCommand="ssh -W %h:%p user@jump.example.com" user@my-server
# or
ssh -i .ssh/id_rsa -J user@jump.example.com user@my-server
Run Code Online (Sandbox Code Playgroud)

系统提示我输入密码user@jump.example.com。如果我提示输入密码,我不会感到惊讶user@my-server

如何为跳转服务器指定身份文件?

Tol*_*mos 5

我建议将以下内容添加到您的 ssh 配置中

Host my_server
        Hostname my-server
        ProxyCommand ssh -W %h:%p jump_server
        User user
        IdentityFile path/to/ssh/identity/file
        Port 22
 
Host jump_server
        Hostname jump.example.com
        User user
        IdentityFile path/to/ssh/identity/file
        Port 22
        
Run Code Online (Sandbox Code Playgroud)

最后连接到您的目标服务器使用

ssh my_server
Run Code Online (Sandbox Code Playgroud)