Reputation: 98
I am trying to automate SSH login for a SSH tunnel using a proxy:
ssh-copy-id
solutionsshpass
works properly when I set the ssh tunnel without ProxyCommand
option but it doesn't work with the option set (Write failed. Broken pipe). The ssh tunnel itself works good with that option, asking me for password. Also tried setting the option in ~/.ssh/ssh_config
with no solution. Here is the oneliner:
sshpass -p $mypass ssh -fN -o StrictHostKeyChecking=no \
-o ProxyCommand="nc -x localhost:8888 %h %p" -R \
*:$rport:$localhostname:$nport $username@$hostname
I tried an Expect
script as described here with no success. I am new to expect and could not figure out the correct quote escapation because I couldn't find a complex spawn
example. Here is what I tried with no luck (and some other variations of quotes):
spawn ssh -fN -o StrictHostKeyChecking=no \
"-o ProxyCommand=\"nc -x localhost:8888 %h %p\"" \
-R *:$rport:$localhostname:$nport $username@$hostname
Can somenone help me? Thank you.
Upvotes: 2
Views: 3552
Reputation: 20688
To use expect:
spawn ssh -fN -o StrictHostKeyChecking=no \
-o "ProxyCommand=nc -x localhost:8888 %h %p" \
-R *:$rport:$localhostname:$nport \
$username@$hostname
Upvotes: 3