1

This comes up with surprising frequency:
I am on a server or other machine via ssh. I want to scp or rsync some files back to my client machine. The problem is that I am behind a firewall and I don't have a port mapped to port 22 on my machine.
It would be great if I could somehow alias the machine that I am connected from in an scp or rsync command something like:

scp fileToBeTransferred LOCALMACHINE:~/temp/

My current process is to issue the command from my local machine (not in an ssh session). It would just be so much faster to be able to issue the scp command from the server because I'm already in the correct directory, I can use file completion, and my credentials are already verified.

My client machine is almost always a Mac running Mountain Lion if that makes a difference.

1 Answer 1

3

you can achieve this with a reverse tunnel to your local ssh port

when connecting to the remote machine add the reverse tunnel with the -R option:

ssh -R 10000:127.0.0.1:22 remoteuser@remotemachine

now, the remote port 10000 is mapped to your local port 22 and you can transfer files from the remote session:

scp -P 10000 yourfile [email protected]:/path/to/target/
4
  • I tried this and it did not work. The connection times out on the scp command. Is there a good way to troubleshoot the port? This reverse tunnel works from behind a firewall? My machine has a private IP, the firewall does NAT. BTW I used 12345 as the port # in both commands (easier on my old eyes)
    – Scott
    Jan 9, 2013 at 18:08
  • fixed the typo. it should work with 12345 too. is your local ssh service running and accepting connections? (not locally firewalled via iptables, selinux and what not)?
    – Gryphius
    Jan 9, 2013 at 18:11
  • ignore the selinux comment, I forgot you're on a mac. I'm not familiar with that os, so maybe someone else can help debug. maybe there is some security feature preventing connections to your local ssh port?
    – Gryphius
    Jan 9, 2013 at 18:24
  • I can ssh to the local machine from other machines on the private network, so the ssh service is running
    – Scott
    Jan 9, 2013 at 18:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .