scp between two remote hosts from my (third) pc











up vote
114
down vote

favorite
35












I have two remote hosts.

host1-> 10.3.0.1

host2-> 10.3.0.2

Both run an ssh server.



The ssh server listens on port 22 in host1 and on port 6969 in host2.
Now, using my local machine, I need to copy something from host1 to host2 without logging into either host1 or host2 via ssh. Something like,



scp user@10.3.0.1:/path/to/file user@10.3.0.2/path/to/file


How can I do this, please note that the two hosts use different ports for ssh.










share|improve this question
























  • Are you asking if you can transfer from a remote host to a remote host, or are you asking how to do it without having to supply a password?
    – glenn jackman
    Dec 10 '13 at 14:22










  • While the -P flag exists to specify the port to use, in case of remote-to-remote transfer, ssh as no defined behaviour on how to specify per-host port...
    – mveroone
    Dec 10 '13 at 15:14















up vote
114
down vote

favorite
35












I have two remote hosts.

host1-> 10.3.0.1

host2-> 10.3.0.2

Both run an ssh server.



The ssh server listens on port 22 in host1 and on port 6969 in host2.
Now, using my local machine, I need to copy something from host1 to host2 without logging into either host1 or host2 via ssh. Something like,



scp user@10.3.0.1:/path/to/file user@10.3.0.2/path/to/file


How can I do this, please note that the two hosts use different ports for ssh.










share|improve this question
























  • Are you asking if you can transfer from a remote host to a remote host, or are you asking how to do it without having to supply a password?
    – glenn jackman
    Dec 10 '13 at 14:22










  • While the -P flag exists to specify the port to use, in case of remote-to-remote transfer, ssh as no defined behaviour on how to specify per-host port...
    – mveroone
    Dec 10 '13 at 15:14













up vote
114
down vote

favorite
35









up vote
114
down vote

favorite
35






35





I have two remote hosts.

host1-> 10.3.0.1

host2-> 10.3.0.2

Both run an ssh server.



The ssh server listens on port 22 in host1 and on port 6969 in host2.
Now, using my local machine, I need to copy something from host1 to host2 without logging into either host1 or host2 via ssh. Something like,



scp user@10.3.0.1:/path/to/file user@10.3.0.2/path/to/file


How can I do this, please note that the two hosts use different ports for ssh.










share|improve this question















I have two remote hosts.

host1-> 10.3.0.1

host2-> 10.3.0.2

Both run an ssh server.



The ssh server listens on port 22 in host1 and on port 6969 in host2.
Now, using my local machine, I need to copy something from host1 to host2 without logging into either host1 or host2 via ssh. Something like,



scp user@10.3.0.1:/path/to/file user@10.3.0.2/path/to/file


How can I do this, please note that the two hosts use different ports for ssh.







linux networking ssh shell scp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 27 '17 at 13:09









7ochem

155111




155111










asked Dec 10 '13 at 13:49









uwais ibrahim

671264




671264












  • Are you asking if you can transfer from a remote host to a remote host, or are you asking how to do it without having to supply a password?
    – glenn jackman
    Dec 10 '13 at 14:22










  • While the -P flag exists to specify the port to use, in case of remote-to-remote transfer, ssh as no defined behaviour on how to specify per-host port...
    – mveroone
    Dec 10 '13 at 15:14


















  • Are you asking if you can transfer from a remote host to a remote host, or are you asking how to do it without having to supply a password?
    – glenn jackman
    Dec 10 '13 at 14:22










  • While the -P flag exists to specify the port to use, in case of remote-to-remote transfer, ssh as no defined behaviour on how to specify per-host port...
    – mveroone
    Dec 10 '13 at 15:14
















Are you asking if you can transfer from a remote host to a remote host, or are you asking how to do it without having to supply a password?
– glenn jackman
Dec 10 '13 at 14:22




Are you asking if you can transfer from a remote host to a remote host, or are you asking how to do it without having to supply a password?
– glenn jackman
Dec 10 '13 at 14:22












While the -P flag exists to specify the port to use, in case of remote-to-remote transfer, ssh as no defined behaviour on how to specify per-host port...
– mveroone
Dec 10 '13 at 15:14




While the -P flag exists to specify the port to use, in case of remote-to-remote transfer, ssh as no defined behaviour on how to specify per-host port...
– mveroone
Dec 10 '13 at 15:14










4 Answers
4






active

oldest

votes

















up vote
189
down vote













In the past, the way in which scp worked, when called (naively) to copy files between remote systems, was very inconvenient: if you wrote, for instance



    scp user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt


scp would first open an ssh session on remote1, and then it would run scp from there to remote2. For this to work, you would have to set up the authorization credentials for remote2 on remote1.



The modern way to do it, instead, ("modern" because it was implemented only a few years ago, and perhaps not everybody has a -3-capable scp) requires two steps.  The first necessary step is to use ~/.ssh/config to set up all options for the connection to both remote1 and remote2, as follows:



    Host remote1.example.org
Port 2222
IdentityFile /path/to/host1-id_rsa

Host remote2.example.org
Port 6969
IdentityFile /path/to/host2-id_rsa


This way it becomes possible to pass all necessary options to the command without ambiguities: for instance, if we had said on the CLI use port 2222 without the above configuration, it would have been unclear whether we were referring to remote1 or to remote2, and likewise for the file containing the cryptgraphic keys. This way the CLI remains tidy and simple.



Secondly, use the -3 option, as follows:



    scp -3 user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt


The -3 option instructs scp to route traffic through the PC on which the command is issued, even though it is a 3rd party to the transfer. This way, authorization credentials must reside only on the issuing PC, the third party.






share|improve this answer



















  • 6




    For future reference: If you copy a file between two hosts that share an identity file (like an EC2 instance), then you don't need the config file. One -i argument is sufficient to connect to both hosts.
    – Artur Czajka
    Aug 8 '14 at 8:13






  • 1




    Also worth noting, for Google Compute Engine, there is support for adding to your ~/.ssh/config file: cloud.google.com/compute/docs/gcloud-compute but I don't think that AWS has the same support
    – modulitos
    Dec 28 '14 at 8:36




















up vote
5
down vote













Last time I tried this, scp wasn't able to do that. Your command line looks okay. This workaround will work:



ssh -p port_on_machine1 user@machine1 "cat /path/to/file/one"|ssh -p port_on_machine2 user@machine2 "cat >/path/to/file/two"





share|improve this answer























  • my scp man page says "Copies between two remote hosts are also permitted."
    – glenn jackman
    Dec 10 '13 at 14:23






  • 1




    Thanks, it is good to hear. To scp you can give a -P flag (it was written by some BSD people, this because its argument handling is so tragic :-( ), but it seems you can't specify different ports on the remote hosts. I am sorry, but I think, only this workaround lefts (or there are a lot of trickier solutions, using ssh but avoiding scp - for example, sftpfs, but they are not the simplest). I extended my workaround with the port settings.
    – peterh
    Dec 10 '13 at 15:11




















up vote
4
down vote













In my case, I was doing a remote to remote copy, withouth the -3 argument.
The port given with the '-P' parameter works with the 1st server, but port 22 is used with the 2nd one.



ssh -P 1234 user@server1.mydomain.com user@server2.otherdomain.com


The solution is to edit the /etc/ssh/ssh_config file in server1 and add these lines:



Host *.otherdomain.com
Port 1234


In this way, the port 1234 is used for both of them. It could be different too.



This solution has better throughput than previous solutions, because communitation is direct.






share|improve this answer























  • perez is there a way to achieve scp through two different ports for the two different remote machines from the comman line?
    – Red Bottle
    Aug 30 at 9:26


















up vote
0
down vote













The source and target can be specified as a URI in the form scp://[user@]host[:port][/path]



so you can run:



scp -3 scp://user@10.3.0.1:22/path/to/file scp://user@10.3.0.2:6969/path/to/file





share|improve this answer





















    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',
    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%2f686394%2fscp-between-two-remote-hosts-from-my-third-pc%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    189
    down vote













    In the past, the way in which scp worked, when called (naively) to copy files between remote systems, was very inconvenient: if you wrote, for instance



        scp user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt


    scp would first open an ssh session on remote1, and then it would run scp from there to remote2. For this to work, you would have to set up the authorization credentials for remote2 on remote1.



    The modern way to do it, instead, ("modern" because it was implemented only a few years ago, and perhaps not everybody has a -3-capable scp) requires two steps.  The first necessary step is to use ~/.ssh/config to set up all options for the connection to both remote1 and remote2, as follows:



        Host remote1.example.org
    Port 2222
    IdentityFile /path/to/host1-id_rsa

    Host remote2.example.org
    Port 6969
    IdentityFile /path/to/host2-id_rsa


    This way it becomes possible to pass all necessary options to the command without ambiguities: for instance, if we had said on the CLI use port 2222 without the above configuration, it would have been unclear whether we were referring to remote1 or to remote2, and likewise for the file containing the cryptgraphic keys. This way the CLI remains tidy and simple.



    Secondly, use the -3 option, as follows:



        scp -3 user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt


    The -3 option instructs scp to route traffic through the PC on which the command is issued, even though it is a 3rd party to the transfer. This way, authorization credentials must reside only on the issuing PC, the third party.






    share|improve this answer



















    • 6




      For future reference: If you copy a file between two hosts that share an identity file (like an EC2 instance), then you don't need the config file. One -i argument is sufficient to connect to both hosts.
      – Artur Czajka
      Aug 8 '14 at 8:13






    • 1




      Also worth noting, for Google Compute Engine, there is support for adding to your ~/.ssh/config file: cloud.google.com/compute/docs/gcloud-compute but I don't think that AWS has the same support
      – modulitos
      Dec 28 '14 at 8:36

















    up vote
    189
    down vote













    In the past, the way in which scp worked, when called (naively) to copy files between remote systems, was very inconvenient: if you wrote, for instance



        scp user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt


    scp would first open an ssh session on remote1, and then it would run scp from there to remote2. For this to work, you would have to set up the authorization credentials for remote2 on remote1.



    The modern way to do it, instead, ("modern" because it was implemented only a few years ago, and perhaps not everybody has a -3-capable scp) requires two steps.  The first necessary step is to use ~/.ssh/config to set up all options for the connection to both remote1 and remote2, as follows:



        Host remote1.example.org
    Port 2222
    IdentityFile /path/to/host1-id_rsa

    Host remote2.example.org
    Port 6969
    IdentityFile /path/to/host2-id_rsa


    This way it becomes possible to pass all necessary options to the command without ambiguities: for instance, if we had said on the CLI use port 2222 without the above configuration, it would have been unclear whether we were referring to remote1 or to remote2, and likewise for the file containing the cryptgraphic keys. This way the CLI remains tidy and simple.



    Secondly, use the -3 option, as follows:



        scp -3 user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt


    The -3 option instructs scp to route traffic through the PC on which the command is issued, even though it is a 3rd party to the transfer. This way, authorization credentials must reside only on the issuing PC, the third party.






    share|improve this answer



















    • 6




      For future reference: If you copy a file between two hosts that share an identity file (like an EC2 instance), then you don't need the config file. One -i argument is sufficient to connect to both hosts.
      – Artur Czajka
      Aug 8 '14 at 8:13






    • 1




      Also worth noting, for Google Compute Engine, there is support for adding to your ~/.ssh/config file: cloud.google.com/compute/docs/gcloud-compute but I don't think that AWS has the same support
      – modulitos
      Dec 28 '14 at 8:36















    up vote
    189
    down vote










    up vote
    189
    down vote









    In the past, the way in which scp worked, when called (naively) to copy files between remote systems, was very inconvenient: if you wrote, for instance



        scp user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt


    scp would first open an ssh session on remote1, and then it would run scp from there to remote2. For this to work, you would have to set up the authorization credentials for remote2 on remote1.



    The modern way to do it, instead, ("modern" because it was implemented only a few years ago, and perhaps not everybody has a -3-capable scp) requires two steps.  The first necessary step is to use ~/.ssh/config to set up all options for the connection to both remote1 and remote2, as follows:



        Host remote1.example.org
    Port 2222
    IdentityFile /path/to/host1-id_rsa

    Host remote2.example.org
    Port 6969
    IdentityFile /path/to/host2-id_rsa


    This way it becomes possible to pass all necessary options to the command without ambiguities: for instance, if we had said on the CLI use port 2222 without the above configuration, it would have been unclear whether we were referring to remote1 or to remote2, and likewise for the file containing the cryptgraphic keys. This way the CLI remains tidy and simple.



    Secondly, use the -3 option, as follows:



        scp -3 user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt


    The -3 option instructs scp to route traffic through the PC on which the command is issued, even though it is a 3rd party to the transfer. This way, authorization credentials must reside only on the issuing PC, the third party.






    share|improve this answer














    In the past, the way in which scp worked, when called (naively) to copy files between remote systems, was very inconvenient: if you wrote, for instance



        scp user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt


    scp would first open an ssh session on remote1, and then it would run scp from there to remote2. For this to work, you would have to set up the authorization credentials for remote2 on remote1.



    The modern way to do it, instead, ("modern" because it was implemented only a few years ago, and perhaps not everybody has a -3-capable scp) requires two steps.  The first necessary step is to use ~/.ssh/config to set up all options for the connection to both remote1 and remote2, as follows:



        Host remote1.example.org
    Port 2222
    IdentityFile /path/to/host1-id_rsa

    Host remote2.example.org
    Port 6969
    IdentityFile /path/to/host2-id_rsa


    This way it becomes possible to pass all necessary options to the command without ambiguities: for instance, if we had said on the CLI use port 2222 without the above configuration, it would have been unclear whether we were referring to remote1 or to remote2, and likewise for the file containing the cryptgraphic keys. This way the CLI remains tidy and simple.



    Secondly, use the -3 option, as follows:



        scp -3 user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt


    The -3 option instructs scp to route traffic through the PC on which the command is issued, even though it is a 3rd party to the transfer. This way, authorization credentials must reside only on the issuing PC, the third party.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Feb 10 '17 at 6:57

























    answered Dec 10 '13 at 18:32









    MariusMatutiae

    37.9k95195




    37.9k95195








    • 6




      For future reference: If you copy a file between two hosts that share an identity file (like an EC2 instance), then you don't need the config file. One -i argument is sufficient to connect to both hosts.
      – Artur Czajka
      Aug 8 '14 at 8:13






    • 1




      Also worth noting, for Google Compute Engine, there is support for adding to your ~/.ssh/config file: cloud.google.com/compute/docs/gcloud-compute but I don't think that AWS has the same support
      – modulitos
      Dec 28 '14 at 8:36
















    • 6




      For future reference: If you copy a file between two hosts that share an identity file (like an EC2 instance), then you don't need the config file. One -i argument is sufficient to connect to both hosts.
      – Artur Czajka
      Aug 8 '14 at 8:13






    • 1




      Also worth noting, for Google Compute Engine, there is support for adding to your ~/.ssh/config file: cloud.google.com/compute/docs/gcloud-compute but I don't think that AWS has the same support
      – modulitos
      Dec 28 '14 at 8:36










    6




    6




    For future reference: If you copy a file between two hosts that share an identity file (like an EC2 instance), then you don't need the config file. One -i argument is sufficient to connect to both hosts.
    – Artur Czajka
    Aug 8 '14 at 8:13




    For future reference: If you copy a file between two hosts that share an identity file (like an EC2 instance), then you don't need the config file. One -i argument is sufficient to connect to both hosts.
    – Artur Czajka
    Aug 8 '14 at 8:13




    1




    1




    Also worth noting, for Google Compute Engine, there is support for adding to your ~/.ssh/config file: cloud.google.com/compute/docs/gcloud-compute but I don't think that AWS has the same support
    – modulitos
    Dec 28 '14 at 8:36






    Also worth noting, for Google Compute Engine, there is support for adding to your ~/.ssh/config file: cloud.google.com/compute/docs/gcloud-compute but I don't think that AWS has the same support
    – modulitos
    Dec 28 '14 at 8:36














    up vote
    5
    down vote













    Last time I tried this, scp wasn't able to do that. Your command line looks okay. This workaround will work:



    ssh -p port_on_machine1 user@machine1 "cat /path/to/file/one"|ssh -p port_on_machine2 user@machine2 "cat >/path/to/file/two"





    share|improve this answer























    • my scp man page says "Copies between two remote hosts are also permitted."
      – glenn jackman
      Dec 10 '13 at 14:23






    • 1




      Thanks, it is good to hear. To scp you can give a -P flag (it was written by some BSD people, this because its argument handling is so tragic :-( ), but it seems you can't specify different ports on the remote hosts. I am sorry, but I think, only this workaround lefts (or there are a lot of trickier solutions, using ssh but avoiding scp - for example, sftpfs, but they are not the simplest). I extended my workaround with the port settings.
      – peterh
      Dec 10 '13 at 15:11

















    up vote
    5
    down vote













    Last time I tried this, scp wasn't able to do that. Your command line looks okay. This workaround will work:



    ssh -p port_on_machine1 user@machine1 "cat /path/to/file/one"|ssh -p port_on_machine2 user@machine2 "cat >/path/to/file/two"





    share|improve this answer























    • my scp man page says "Copies between two remote hosts are also permitted."
      – glenn jackman
      Dec 10 '13 at 14:23






    • 1




      Thanks, it is good to hear. To scp you can give a -P flag (it was written by some BSD people, this because its argument handling is so tragic :-( ), but it seems you can't specify different ports on the remote hosts. I am sorry, but I think, only this workaround lefts (or there are a lot of trickier solutions, using ssh but avoiding scp - for example, sftpfs, but they are not the simplest). I extended my workaround with the port settings.
      – peterh
      Dec 10 '13 at 15:11















    up vote
    5
    down vote










    up vote
    5
    down vote









    Last time I tried this, scp wasn't able to do that. Your command line looks okay. This workaround will work:



    ssh -p port_on_machine1 user@machine1 "cat /path/to/file/one"|ssh -p port_on_machine2 user@machine2 "cat >/path/to/file/two"





    share|improve this answer














    Last time I tried this, scp wasn't able to do that. Your command line looks okay. This workaround will work:



    ssh -p port_on_machine1 user@machine1 "cat /path/to/file/one"|ssh -p port_on_machine2 user@machine2 "cat >/path/to/file/two"






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Aug 22 '16 at 18:33









    MariusMatutiae

    37.9k95195




    37.9k95195










    answered Dec 10 '13 at 14:17









    peterh

    1,36482137




    1,36482137












    • my scp man page says "Copies between two remote hosts are also permitted."
      – glenn jackman
      Dec 10 '13 at 14:23






    • 1




      Thanks, it is good to hear. To scp you can give a -P flag (it was written by some BSD people, this because its argument handling is so tragic :-( ), but it seems you can't specify different ports on the remote hosts. I am sorry, but I think, only this workaround lefts (or there are a lot of trickier solutions, using ssh but avoiding scp - for example, sftpfs, but they are not the simplest). I extended my workaround with the port settings.
      – peterh
      Dec 10 '13 at 15:11




















    • my scp man page says "Copies between two remote hosts are also permitted."
      – glenn jackman
      Dec 10 '13 at 14:23






    • 1




      Thanks, it is good to hear. To scp you can give a -P flag (it was written by some BSD people, this because its argument handling is so tragic :-( ), but it seems you can't specify different ports on the remote hosts. I am sorry, but I think, only this workaround lefts (or there are a lot of trickier solutions, using ssh but avoiding scp - for example, sftpfs, but they are not the simplest). I extended my workaround with the port settings.
      – peterh
      Dec 10 '13 at 15:11


















    my scp man page says "Copies between two remote hosts are also permitted."
    – glenn jackman
    Dec 10 '13 at 14:23




    my scp man page says "Copies between two remote hosts are also permitted."
    – glenn jackman
    Dec 10 '13 at 14:23




    1




    1




    Thanks, it is good to hear. To scp you can give a -P flag (it was written by some BSD people, this because its argument handling is so tragic :-( ), but it seems you can't specify different ports on the remote hosts. I am sorry, but I think, only this workaround lefts (or there are a lot of trickier solutions, using ssh but avoiding scp - for example, sftpfs, but they are not the simplest). I extended my workaround with the port settings.
    – peterh
    Dec 10 '13 at 15:11






    Thanks, it is good to hear. To scp you can give a -P flag (it was written by some BSD people, this because its argument handling is so tragic :-( ), but it seems you can't specify different ports on the remote hosts. I am sorry, but I think, only this workaround lefts (or there are a lot of trickier solutions, using ssh but avoiding scp - for example, sftpfs, but they are not the simplest). I extended my workaround with the port settings.
    – peterh
    Dec 10 '13 at 15:11












    up vote
    4
    down vote













    In my case, I was doing a remote to remote copy, withouth the -3 argument.
    The port given with the '-P' parameter works with the 1st server, but port 22 is used with the 2nd one.



    ssh -P 1234 user@server1.mydomain.com user@server2.otherdomain.com


    The solution is to edit the /etc/ssh/ssh_config file in server1 and add these lines:



    Host *.otherdomain.com
    Port 1234


    In this way, the port 1234 is used for both of them. It could be different too.



    This solution has better throughput than previous solutions, because communitation is direct.






    share|improve this answer























    • perez is there a way to achieve scp through two different ports for the two different remote machines from the comman line?
      – Red Bottle
      Aug 30 at 9:26















    up vote
    4
    down vote













    In my case, I was doing a remote to remote copy, withouth the -3 argument.
    The port given with the '-P' parameter works with the 1st server, but port 22 is used with the 2nd one.



    ssh -P 1234 user@server1.mydomain.com user@server2.otherdomain.com


    The solution is to edit the /etc/ssh/ssh_config file in server1 and add these lines:



    Host *.otherdomain.com
    Port 1234


    In this way, the port 1234 is used for both of them. It could be different too.



    This solution has better throughput than previous solutions, because communitation is direct.






    share|improve this answer























    • perez is there a way to achieve scp through two different ports for the two different remote machines from the comman line?
      – Red Bottle
      Aug 30 at 9:26













    up vote
    4
    down vote










    up vote
    4
    down vote









    In my case, I was doing a remote to remote copy, withouth the -3 argument.
    The port given with the '-P' parameter works with the 1st server, but port 22 is used with the 2nd one.



    ssh -P 1234 user@server1.mydomain.com user@server2.otherdomain.com


    The solution is to edit the /etc/ssh/ssh_config file in server1 and add these lines:



    Host *.otherdomain.com
    Port 1234


    In this way, the port 1234 is used for both of them. It could be different too.



    This solution has better throughput than previous solutions, because communitation is direct.






    share|improve this answer














    In my case, I was doing a remote to remote copy, withouth the -3 argument.
    The port given with the '-P' parameter works with the 1st server, but port 22 is used with the 2nd one.



    ssh -P 1234 user@server1.mydomain.com user@server2.otherdomain.com


    The solution is to edit the /etc/ssh/ssh_config file in server1 and add these lines:



    Host *.otherdomain.com
    Port 1234


    In this way, the port 1234 is used for both of them. It could be different too.



    This solution has better throughput than previous solutions, because communitation is direct.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 27 '16 at 7:47

























    answered Jan 26 '16 at 14:18









    david.perez

    15810




    15810












    • perez is there a way to achieve scp through two different ports for the two different remote machines from the comman line?
      – Red Bottle
      Aug 30 at 9:26


















    • perez is there a way to achieve scp through two different ports for the two different remote machines from the comman line?
      – Red Bottle
      Aug 30 at 9:26
















    perez is there a way to achieve scp through two different ports for the two different remote machines from the comman line?
    – Red Bottle
    Aug 30 at 9:26




    perez is there a way to achieve scp through two different ports for the two different remote machines from the comman line?
    – Red Bottle
    Aug 30 at 9:26










    up vote
    0
    down vote













    The source and target can be specified as a URI in the form scp://[user@]host[:port][/path]



    so you can run:



    scp -3 scp://user@10.3.0.1:22/path/to/file scp://user@10.3.0.2:6969/path/to/file





    share|improve this answer

























      up vote
      0
      down vote













      The source and target can be specified as a URI in the form scp://[user@]host[:port][/path]



      so you can run:



      scp -3 scp://user@10.3.0.1:22/path/to/file scp://user@10.3.0.2:6969/path/to/file





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        The source and target can be specified as a URI in the form scp://[user@]host[:port][/path]



        so you can run:



        scp -3 scp://user@10.3.0.1:22/path/to/file scp://user@10.3.0.2:6969/path/to/file





        share|improve this answer












        The source and target can be specified as a URI in the form scp://[user@]host[:port][/path]



        so you can run:



        scp -3 scp://user@10.3.0.1:22/path/to/file scp://user@10.3.0.2:6969/path/to/file






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 3 at 15:41









        user3403199

        1




        1






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f686394%2fscp-between-two-remote-hosts-from-my-third-pc%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

            How do I know what Microsoft account the skydrive app is syncing to?

            When does type information flow backwards in C++?

            Grease: Live!