Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|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

3 Answers 3

up vote 1 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.

share|improve this answer

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.

share|improve this answer

(Not directly related to this but..) you can also create a Reverse SSH Tunnel.

on Remote server:

ssh -fN -R 7000:localhost:22 username@yourMachine-ipaddress

Now do an ssh connection request from your machine to your own machine at port 7000:

ssh username@localhost -p 7000
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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