How to scp with a second remote host

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

    I don't know of any way to copy the file directly in one single command, but if you can concede to running an SSH instance in the background to just keep a port forwarding tunnel open, then you could copy the file in one command.

    Like this:

    # First, open the tunnel
    ssh -L 1234:remote2:22 -p 45678 user1@remote1
    # Then, use the tunnel to copy the file directly from remote2
    scp -P 1234 user2@localhost:file .
    

    Note that you connect as user2@localhost in the actual scp command, because it is on port 1234 on localhost that the first ssh instance is listening to forward connections to remote2. Note also that you don't need to run the first command for every subsequent file copy; you can simply leave it running.

    0 讨论(0)
提交回复
热议问题