Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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:127.0.0.1:22 user@remote

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

scp -P2222 file 127.0.0.1:/path/
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

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.