SSH ProxyCommand在连接后更改用户

时间:2017-01-29 13:22:12

标签: ssh terminal

由于防火墙的限制,我需要能够通过其他主机连接到主机。我目前能够成功连接ProxyCommand选项。但是现在我需要在连接到目标主机后更改用户,从user_one到user_two。

我当前的配置文件:

Host destination
Hostname destination.example.com
User user_one
ProxyCommand ssh -W %h:%p fw.example.com
IdentityFile /Users/local_user/.ssh/id_rsa

我拥有以user_one身份连接的所有必要密钥,但我需要sudo su user_two才能以该用户身份登录。我需要充当该用户才能通过sftp写入文件。 (这是一个网络服务器)。

那么如何自动切换到user_two?

1 个答案:

答案 0 :(得分:0)

您可以在登录后立即使用RemoteCommand切换用户。您的.ssh/config将是:

Host destination
    Hostname destination.example.com
    User user_one
    ProxyCommand ssh -W %h:%p fw.example.com
    IdentityFile /Users/local_user/.ssh/id_rsa
    RemoteCommand sudo su - user_two
    RequestTTY yes

请注意,如果远程服务器requires a TTY在运行RequestTTY yes时可能还需要添加sudo