My setup is the following:

  • node A is where I start
  • node B is the gateway machine
  • node C is the destination.

From Ato B I have setup SSH public key authentication but from B to C I am not allowed to.

So from node A I use the following incantation which actually works from a different machine (Ubuntu 14.04):

sshpass -p secretpass ssh -oProxyCommand="ssh -W %h:%p username@B" username@C

… however, when I try from a different location with another machine (Ubuntu 16.04 - though I doubt that's relevant), the invocation of sshpass promptly returns without any kind of output and an exit code (obtained with echo $?) of 6.

More puzzling is the fact that if I do the steps separately, they succeed:

A: $ ssh username@B   (directly access B without being prompted for password)
B: $ ssh username@C   (prompted for password, provided 'secretpass')
C: $                  (reached my destination)
  • I don't have a similar setup to test, but will ssh -A -t username@B sshpass -p secretpass ssh -A username@C work? – Paul H. Nov 16 '16 at 16:28
  • sshpass is not available on node B nor can I install it. – Marcus Junius Brutus Nov 16 '16 at 16:50

Ok, so I figured out what was the matter. Since I was using this script for the first time on this machine I had to first do the following (without sshpass):

ssh -oProxyCommand="ssh -W %h:%p username@B" username@C

I was then prompted with:

The authenticity of host 'C <no hostip for proxy command>)' can't be established.

RSA key fingerprint is SHA256:... .

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'C' (RSA) to the list of known hosts

… once I accepted the above, I was able to use the incantation I inquire about in my question without further problems.

So this failure was due to the incantation not being able to answer to the authenticity prompt that only appears once.

  • Please remember to log in once with all used users. At first I only did it with a normal user and then wondered why the script (executed with sudo/root!) didn't work. -_- – uav Jun 25 at 13:26

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.