Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sshpass with proxycommand returns without running anything

Tags:

ssh

proxy

sshpass

In our environments, we have several servers in production. Every time I want to search for something, it may be in 1 of 4 different servers. I am creating a script to automate this search, so that I directly know which server is involved.

I am connecting through a jumphost.

So far the following command works fine :

$ ssh -oProxyCommand="ssh -W %h:%p user@jumphost" user@server "ls"

Now, because I have to run this several times, I am searching for a way to only have to use the password once.

Both the jumphost and the server require the same password, and public keys are not an option (not allowed, I literally cannot do it).

I have been reading about sshpass for this and am trying this :

$ sshpass -p password ssh -oProxyCommand="ssh -W %h:%p user@jumphost" user@server "ls"

(I know -p is not safe and will use -e of -f as soon as I am successful with this step).

When I do this, I can login in both systems but the command returns before I see the result of ls. I have tried to have the -t option to ssh without any success.

I have also tried the -J option from ssh, with the same results (command returns without returning any results).

$ sshpass -p password ssh -J user@jumphost user@server "ls"

Any suggestions?

EDIT:

Solution was to use sshpass twice :

$ sshpass -p password_server ssh -oProxyCommand="sshpass -p password_jumphost ssh -W %h:%p user@jumphost" user@server "ls"
like image 482
jlengrand Avatar asked Oct 14 '25 20:10

jlengrand


1 Answers

Try running ssh in verbose mode:

ssh -vvv -oProxyCommand="ssh -W %h:%p user@jumphost" user@server "ls"

I'm sure it will show something of interest. A hook with which you can figure this out.

like image 137
Roland van Laar Avatar answered Oct 17 '25 21:10

Roland van Laar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!