How to scp with a second remote host

前端 未结 7 636
终归单人心
终归单人心 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:02

    This will do the trick:

    scp -o 'Host remote2' -o 'ProxyCommand ssh user@remote1 nc %h %p' \ 
        user@remote2:path/to/file .
    

    To SCP the file from the host remote2 directly, add the two options (Host and ProxyCommand) to your ~/.ssh/config file (see also this answer on superuser). Then you can run:

    scp user@remote2:path/to/file .
    

    from your local machine without having to think about remote1.

提交回复
热议问题