I am trying to automate SSH login for a SSH tunnel using a proxy:
- I do not want to use the
ssh-copy-id
solution sshpass
works properly when I set the ssh tunnel withoutProxyCommand
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 complexspawn
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.