2

I am trying to automate SSH login for a SSH tunnel using a proxy:

  1. I do not want to use the ssh-copy-id solution
  2. sshpass 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
    
  3. 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.

pynexj
  • 19,215
  • 5
  • 38
  • 56

1 Answers1

3

To use expect:

spawn ssh -fN -o StrictHostKeyChecking=no \
    -o "ProxyCommand=nc -x localhost:8888 %h %p" \
    -R *:$rport:$localhostname:$nport \
    $username@$hostname
pynexj
  • 19,215
  • 5
  • 38
  • 56
  • it works! I have another issue though; when I look in the sshd logs I see that the password is accepted, connection is opened and closed immediately afterwards(and thus the tunnel is not established). If I remove the "close $spawn_id" line, I can't see the accepted password log anymore. Do you have any idea why the session is closed that fast? http://pastebin.com/vFYimSu0 – Mititelu Stefan Feb 22 '15 at 22:58