How to change the user after connecting to the jump host when using ProxyCommand

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












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.










share|improve this question
























  • 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















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.










share|improve this question
























  • 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












0








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.










share|improve this question
















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.







linux ssh ansible






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 26 at 10:42







Riddhesh

















asked Feb 25 at 18:06









RiddheshRiddhesh

12




12












  • 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

















  • 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
















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






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, 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





@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





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





@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










1 Answer
1






active

oldest

votes


















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.






share|improve this answer























  • 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








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502959%2fhow-to-change-the-user-after-connecting-to-the-jump-host-when-using-proxycommand%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









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.






share|improve this answer























  • 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
















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.






share|improve this answer























  • 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














0












0








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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 26 at 4:43









GarethHumphriesAccGarethHumphriesAcc

1595




1595












  • 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


















  • 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

















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





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






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


















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502959%2fhow-to-change-the-user-after-connecting-to-the-jump-host-when-using-proxycommand%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?