I am trying to copy a file from 10.10.10.99:/home/shantanu/ to the localhost. The only problem is that I need to tunnel the connection through 10.10.10.98 Something like this does not work....

ssh shantanu@10.10.10.98 "ssh shantanu@10.10.10.99 cp /home/shantanu/test.txt . "

The thread "ssh tunnel via multiple hops" is too confusing.

http://superuser.com/questions/96489/ssh-tunnel-via-multiple-hops

link|improve this question

1  
That's because the accepted solution is not a very good one. – Ignacio Vazquez-Abrams Jun 8 '11 at 8:41
feedback

2 Answers

up vote 0 down vote accepted

Don't use "cp" for copying files between SSH-enabled hosts, use scp. Something like this should suffice for your needs right now:

ssh -f shantanu@10.10.10.98 -L 41111:10.10.10.99:22 -N
scp -P 41111 shantanu@localhost:/home/shantanu/test.txt .

It should be noted that the first command creates a tunnel (accessible only from your localhost, but still) that you might want to close after transferring the files. Or leave it open, it's not a huge security risk since you still have to auth against the second host to use it.

link|improve this answer
feedback

Just pipe the local file through a chain of SSH pipes to its final destination:

ssh shantanu@10.10.10.98 "ssh shantanu@10.10.10.99 'cat >test.txt'" </home/shantanu/test.txt

The only tricky part can be the double quoting required to get the shell redirection executed on the target machine.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.