Search code examples
shellsftpscppublic-keywinscp

Scp from Linux to Windows machine using jumphost


Below command is working, I am able to download file from jumphost to my current directory in Windows machine using .pub file

scp -r -i user_202201281017.pub user@jumphost_ip_address:/home/user/check-job-status.sh .

As of now I am copying file to jumphost server using sftp, then doing scp to my Windows machine. I would like to bypass jumphost and want to use 2nd hop to transfer file to Windows machine like below command

scp -r -i user_202201281017.pub user@jumphost_ip_address,user@file_present_at_original_server:/home/user/check-job-status.sh .

Error:

ssh: connect to host file_present_at_original_server port 22: Connection timed out


Solution

  • If you have OpenSSH 8.0 and newer, you can use -J (jump) switch:

    scp -r -i user_202201281017.pub -J user@jumphost_ip_address user@file_present_at_original_server:/home/user/check-job-status.sh .
    

    With older version, but at least 7.3, use ProxyJump directive:

    scp ... -o ProxyJump=user@jumphost_ip_address
    

    For more options, see Does OpenSSH support multihop login?


    With Windows build of OpenSSH (Win32-OpenSSH), you need the latest version in any case, as earlier versions had broken jump host support. They fail with:

    CreateProcessW failed error:2 posix_spawn: No such file or directory