How to use sshpass for chained connection?

4

I have two customer's machines, $gateway and $server, the second one is only accessible from the first one. Public key auth is unavailable on both systems. So, to execute some $command on the server I need to run ssh $gateway ssh $server $command and then type two passwords. I can use sshpass, but it will handle only the first connection and I still need to enter the second password by hand.

How can I make completely noninteractive (without manually entering passwords) ssh access to the server?

The only way I see is to use tunnels, but they are hard to keep alive because of unstable internet connection.

Equidamoid

Posted 2013-06-11T10:27:57.223

Reputation: 274

What kind of an admin turns off public-key auth?.. (Maybe the servers have something else enabled, like gssapi?) – user1686 – 2013-06-11T12:18:34.363

I know that someone will ask this =) – Equidamoid – 2013-06-11T12:35:20.700

It's a very specific embedded system, maybe there is a way to enable keys but I don't want to touch anything except things I was explicitly allowed to touch. – Equidamoid – 2013-06-11T12:43:35.060

Answers

4

Try:

ssh -oProxyCommand="ssh -W %h:%p $gateway" $server command

For example:

ssh -oProxyCommand="ssh -W %h:%p albert@gateway.uibk.ac.at" root@hidden.uibk.ac.at command

This will use proxy the ssh connection to $server over another ssh command, without actually creating a tunnel. This makes sure that both ssh clients run locally, thereby using sshpass.

Albert Peschar

Posted 2013-06-11T10:27:57.223

Reputation: 198

1Great! Thank you! (to use with sshpass one just need to replace ssh with sshpass -p <corresponding_password> ssh) – Equidamoid – 2013-06-11T11:28:07.323

Ooops, I've found something like ssh $gateway rsync $file $server:. Any idea how to make it work? – Equidamoid – 2013-06-11T11:40:11.743

If $file is local, you could use rsync's -e option to use a different ssh command. Just check the manual using man rsync. – Albert Peschar – 2013-06-14T07:07:49.790

No, it isn't. It is placed on $gateway. Connection localhost <-> $gateway is terribly slow, so 'download the file to my laptop and then put it to the server' is not an option – Equidamoid – 2013-06-15T07:58:11.707

sshpass -p $password $gateway rsync -e "sshpass -p $password" $file $server: ? – Albert Peschar – 2013-06-16T11:25:20.227