How to scp with a second remote host

前端 未结 7 638
终归单人心
终归单人心 2020-12-04 05:55

I wonder if there is a way for me to SCP the file from remote2 host directly from my local machine by going through a remote1 host.

The networks only allow connectio

7条回答
  •  被撕碎了的回忆
    2020-12-04 06:11

    There is a new option in scp that add recently for exactly this same job that is very convenient, it is -3.

    TL;DR For the current host that has authentication already set up in ssh config files, just do:

    scp -3 remote1:file remote2:file
    

    Your scp must be from recent versions.

    All other mentioned technique requires you to set up authentication from remote1 to remote2 or vice versa, which not always is a good idea.
    Argument -3 means you want to move files from two remote hosts by using current host as intermediary, and this host actually does the authentication to both remote hosts, so they don't have to have access to each other.
    You just have to setup authentication in ssh config files, which is fairly easy and well documented, and then just run the command in TL;DR

    The source for this answer is https://superuser.com/a/686527/713762

提交回复
热议问题