How to transfer files remote to local using SSH












1















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
















1















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














1












1








1


1






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














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).







ssh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 21 '12 at 17:58









UnixNewbie2012UnixNewbie2012

3326




3326













  • 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



















  • 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

















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





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





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





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





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





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










3 Answers
3






active

oldest

votes


















6














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



















1














You can also do the opposite, to grab a file from a remote machine to the local machine,



ssh -L 2222:user@192.168.1.37:22 user@remoteserver.com -N &
scp -P 2222 127.0.0.1:/path/to/file/on/remote/machine.diff /tmp


The ssh command sets up a tunnel from localhost:2222 to the remote machine 192.168.1.37 behind the net facing server remoteserver.com. The second command lets you copy it locally.



Some good examples and tips here, and how to configure it in ~/.ssh/config to automate it.






share|improve this answer































    0














    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








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f478028%2fhow-to-transfer-files-remote-to-local-using-ssh%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    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
















    6














    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














    6












    6








    6







    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













    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












    share|improve this answer



    share|improve this answer










    answered Sep 21 '12 at 18:33









    Ansgar WiechersAnsgar Wiechers

    4,64021321




    4,64021321













    • 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



















    • 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

















    I did not know that. Much simpler!

    – ND Geek
    Sep 21 '12 at 18:36





    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





    Wow cool. This is the way to go.

    – UnixNewbie2012
    Sep 21 '12 at 18:45













    1














    You can also do the opposite, to grab a file from a remote machine to the local machine,



    ssh -L 2222:user@192.168.1.37:22 user@remoteserver.com -N &
    scp -P 2222 127.0.0.1:/path/to/file/on/remote/machine.diff /tmp


    The ssh command sets up a tunnel from localhost:2222 to the remote machine 192.168.1.37 behind the net facing server remoteserver.com. The second command lets you copy it locally.



    Some good examples and tips here, and how to configure it in ~/.ssh/config to automate it.






    share|improve this answer




























      1














      You can also do the opposite, to grab a file from a remote machine to the local machine,



      ssh -L 2222:user@192.168.1.37:22 user@remoteserver.com -N &
      scp -P 2222 127.0.0.1:/path/to/file/on/remote/machine.diff /tmp


      The ssh command sets up a tunnel from localhost:2222 to the remote machine 192.168.1.37 behind the net facing server remoteserver.com. The second command lets you copy it locally.



      Some good examples and tips here, and how to configure it in ~/.ssh/config to automate it.






      share|improve this answer


























        1












        1








        1







        You can also do the opposite, to grab a file from a remote machine to the local machine,



        ssh -L 2222:user@192.168.1.37:22 user@remoteserver.com -N &
        scp -P 2222 127.0.0.1:/path/to/file/on/remote/machine.diff /tmp


        The ssh command sets up a tunnel from localhost:2222 to the remote machine 192.168.1.37 behind the net facing server remoteserver.com. The second command lets you copy it locally.



        Some good examples and tips here, and how to configure it in ~/.ssh/config to automate it.






        share|improve this answer













        You can also do the opposite, to grab a file from a remote machine to the local machine,



        ssh -L 2222:user@192.168.1.37:22 user@remoteserver.com -N &
        scp -P 2222 127.0.0.1:/path/to/file/on/remote/machine.diff /tmp


        The ssh command sets up a tunnel from localhost:2222 to the remote machine 192.168.1.37 behind the net facing server remoteserver.com. The second command lets you copy it locally.



        Some good examples and tips here, and how to configure it in ~/.ssh/config to automate it.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 18 at 15:18









        Steeve McCauleySteeve McCauley

        1113




        1113























            0














            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
















            0














            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














            0












            0








            0







            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













            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












            share|improve this answer



            share|improve this answer










            answered Sep 21 '12 at 18:25









            ND GeekND Geek

            6581511




            6581511













            • 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



















            • 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

















            That won't be necessary.

            – Ansgar Wiechers
            Sep 21 '12 at 18:34





            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





            One other note: make sure that Remote Login is enabled via System Preferences if on a mac.

            – UnixNewbie2012
            Sep 21 '12 at 18:34


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f478028%2fhow-to-transfer-files-remote-to-local-using-ssh%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Список кардиналов, возведённых папой римским Каликстом III

            Deduzione

            Mysql.sock missing - “Can't connect to local MySQL server through socket”