Copying a file from AWS ec2 into a private subnet over ssh tunnel

In one terminal session establish ssh tunnel to deployment server through jumphost:

ssh -L 1234:10.16X.server.privateIP:22 -p 22 ec2-user@54.25X.jumphost.publicIP

it logged me into jumphost, ec2-user is the user on the jumphost. 1234 is the port on localhost where the tunnel is now established.

In other terminal session on localhost, do the command:

scp -P 1234 ubuntu@localhost:/var/lib/jenkins/branches/master/path/to/deployment/package .

ubuntu is the user on deployment server which in in private subnet. Both servers are listening to ssh on port 22.

Voila!

Now you can close the tunnel in first terminal session:

[ec2-user@ip-10-161-jumphost-privateIP ~]$ exit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: