How to scp with a second remote host

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

    With openssh version 7.3 and up it is easy. Use ProxyJump option in the config file.

    # Add to ~/.ssh/config 
    Host bastion
        Hostname bastion.client.com
        User userForBastion
        IdentityFile ~/.ssh/bastion.pem
    
    Host appMachine
        Hostname appMachine.internal.com
        User bastion
        ProxyJump bastion                   # openssh 7.3 version new feature ProxyJump
        IdentityFile ~/.ssh/appMachine.pem. #no need to copy pem file to bastion host  
    

    Commands to run to login or copy

    ssh appMachine   # no need to specify any tunnel. 
    scp helloWorld.txt appMachine:.   # copy without intermediate jumphost/bastion host copy.** 
    

    ofcourse you can specify bastion Jump host using option "-J" to ssh command, if not configured in config file.

    Note scp does not seems to support "-J" flag as of now. (i could not find in man pages. However above scp works with config file setting)

提交回复
热议问题