2

I'm wanting to scp a file from my local machine to a remote server, using an intermediary tunnel. I've tried a few options already suggested, but none seem to work.

Breakdown: local machine

  • The file to copy is called localfile.txt
  • ssh connection to intermediary machine already exists, and is being re-used via ControlPath/ControlMaster

intermediary machine

  • The identity to use to log in to the destination server is in ~/.ssh/identityfileforremotemachine

remote machine

  • The destination will be at /home/username/remotefile.txt

I feel like I'm almost there and missing something

2 Answers 2

2

You didn't say what commands you tried, but any openssh >= 7.3, the following is almost certain to work, though you will first need to tear down the existing control master using ssh me@internediate -O exit.

ssh -i .ssh/blahblah -J me@intermediate me@finaldestination

See https://security.stackexchange.com/a/223005/88917 for some explanation of that -J

1
1

Create a tunnel from your local machine to the remote machine via the intermediate machine. The local machine will create an SSH session that will bind a TCP tunnel from port 2222 on your local machine to port 22 on the remote machine. You can then ssh/scp over the tunnel to achieve the copy.

  1. Setup tunnel: From local machine:

    ssh -L 2222:remote_machine:22 -N user@intermediate_machine

  2. Copy over tunnel

    a. Create a new terminal/tab/shell on your local machine:

    scp -P 2222 localfile.txt remote_user@localhost:remotefile.txt
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .