Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What terminal command can I use to transfer a directory from a remote machine (linux) to my local machine (mac)? Most importantly, I'd like to do this from the command line while SSH'ed into the remote machine. I know how to use SCP while on my local machine command line, but I have no idea how I'd use it from the remote machine (nor what my local path would be).

share|improve this question
Is your local machine behind a firewall? Is there a particular reason you need to do this while remotely logged in? – ND Geek Sep 21 '12 at 18:02
I'm using su to access the files, so didn't think I could do this while not logged in. – UnixNewbie2012 Sep 21 '12 at 18:04
Ah. Well, if you have read access to the files while not root, you should still be able to access them via scp from your local machine. If they're not readable by anyone that isn't root, then yeah, you'd need to run the copy as root. – ND Geek Sep 21 '12 at 18:06
Right. So I have to run the copy as root. Seems like SCP still works if I know the full path to my mac, right? How would I find this? – UnixNewbie2012 Sep 21 '12 at 18:07
Well, that goes back to my first question, are you behind a firewall/router, or is your Mac publicly accessible (if you're at home, are you directly plugged into your modem?)? – ND Geek Sep 21 '12 at 18:08
up vote 3 down vote accepted

Start the sshd on your local computer if you hadn't already done this. Then start a second session from your local computer to the remote computer:

ssh -R 2222: user@remote

This forwards the remote port 2222 to the sshd listening on on your local computer, creating a reverse tunnel. Then run scp on the remote computer:

scp -P2222 file
share|improve this answer
I did not know that. Much simpler! – ND Geek Sep 21 '12 at 18:36
Wow cool. This is the way to go. – UnixNewbie2012 Sep 21 '12 at 18:45

If you're locally behind a router/firewall that is giving you a private IP address, you'll need to configure the router to NAT a port to map to your local port 22. You can then access it from the remote computer by addressing your public IP address on whatever port you choose (you can map port 22 directly, but I generally personally recommend avoiding this as standard server ports are common targets for malware trying to find a way in).

share|improve this answer
That won't be necessary. – Ansgar Wiechers Sep 21 '12 at 18:34
One other note: make sure that Remote Login is enabled via System Preferences if on a mac. – UnixNewbie2012 Sep 21 '12 at 18:34

You must log in to answer this question.

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