Skip to content

Instantly share code, notes, and snippets.

@jenseickmeyer
Created December 27, 2018 15:43
Show Gist options
  • Save jenseickmeyer/7da3d0a98adf4e0988066c7962cdfff2 to your computer and use it in GitHub Desktop.
Save jenseickmeyer/7da3d0a98adf4e0988066c7962cdfff2 to your computer and use it in GitHub Desktop.

Use a Bastion Host

Login

At least two techniques exist for jumping "through" a bastion host to a "hidden" server. In the following examples, the bastion host has the hostname BastionHost whereas the target host has the hostname TargetHost.

Agent Forwarding

First, we log in to the bastion host

ssh -A -i key.pem ec2-user@BastionHost

From there, we can simply login to the target host

ssh TargetHost

Proxy

Instead of logging in to the bastion host it is possible to use it as a proxy by using the following command

ssh -i key.pem -J ec2-user@BastionHost ec2-user@TargetHost

Run commands

To run commands on the target host use the following command

ssh -i key.pem -J ec2-user@BastionHost ec2-user@TargetHost uname -a

In this case the command uname -a has been run on the remote server.

Copy files

For copying file to or from the target host it is possible to use the following command

scp -i key.pem -o "ProxyCommand ssh ec2-user@BastionHost -W %h:%p" file ec2-user@TargetHost:~/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment