Reputation: 4049
I need to be able to connect to a host through another host because of firewall limitations. I'm currently able to connect successfully with the ProxyCommand option. But now I need to change the user after connecting to the destination host, from user_one to user_two.
My current config file:
Host destination
Hostname destination.example.com
User user_one
ProxyCommand ssh -W %h:%p fw.example.com
IdentityFile /Users/local_user/.ssh/id_rsa
I have all the necessary keys for connecting as user_one, but I need to sudo su user_two
to be able to login as that user. And I need to act as that user in order to write files through sftp. (This is a webserver).
So how can I automatically switch to user_two?
Upvotes: 6
Views: 4246
Reputation: 1377
You can use RemoteCommand
to switch users immediately after logging in. Your .ssh/config
would then be:
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
Note that you may also need to add RequestTTY yes
, if the remote server requires a TTY when running sudo
.
Upvotes: 2