0

My normal flow is like:

ssh jumphost
sudo -iHu jump_user
ssh target_user@targethost
Do some task

How to do this using ProxyCommand? I have tried:

ssh target_user@target_host -o ProxyCommand="ssh jumphost 'sudo -iHu jump_user' nc -w 120 %h %p"

But it's asking password for target_user as user is not changing to jump_user on jump_host. How to do it? My final aim is to use this as ansible_ssh_common_args so I can run tasks on target server.

  • What version of OpenSSH are you using? And why do you need to change user on the jump host? – Kusalananda Feb 25 at 18:16
  • @Kusalananda, It's 7.4 – Riddhesh Feb 25 at 18:18
  • @Kusalananda, I can't directly ssh to target_host with my user, I need to ssh to the jumphost first, that also I can't ssh with jump_user. But I can run sudo -iHu jump_user and after that only I can ssh into target_host. It's security related, and I don't know much about it. – Riddhesh Feb 25 at 18:28
  • Is jump_user not able to use ssh from the jumphost host? – Kusalananda Feb 26 at 10:46
  • @Kusalananda No, that's where I'm also confused. I have to follow the above flow which asks no passwords. Can't ssh jump_user@targethost from jumphost or can't ssh jump_user@jump_host from myhost. Maybe some authorized_keys are setup. – Riddhesh Feb 26 at 10:54
0

Create a .ssh/config file on the jumphost with:

Host targethost
  User target_user

Or whatever is appropriate for your setup. Other settings like keepalives, agent forwarding, multiplexing etc can also be configured here to make your life easier.

man ssh_config is the documentation you want to consult.

  • The problem is on jump_host user is not changed to jump_user. Really sorry, it wasn't clear in my question. I have edited it. – Riddhesh Feb 26 at 10:44
  • So, sudo -i gives you an interactive shell - that's not what you want here. Have you tried with something like ssh jumphost 'sudo -u jump_user "ssh target_user@targethost do-some-task"' ? Get that form working, and then adjust your .ssh/config/proxy command based on it. – GarethHumphriesAcc Feb 26 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.