Skip to content

Instantly share code, notes, and snippets.

@ozbillwang
Last active December 8, 2015 23:21
Show Gist options
  • Save ozbillwang/d70b4aa03f9ffba89112 to your computer and use it in GitHub Desktop.
Save ozbillwang/d70b4aa03f9ffba89112 to your computer and use it in GitHub Desktop.
Easy way to connect to ec2 instance in office behind proxy and at home

AWS ec2 instances normally have both public DNS name and public IP address. We can wisely use them for office environment which may behind proxy and directly connect from home.

Set below code in .ssh/config and enjoy convenience.

Suppose the instance has name as

ec2-54-252-146-85.ap-southeast-2.compute.amazonaws.com
54.252.146.85

So you can set as below

Host ec2-54-252-146-85.ap-southeast-2.compute.amazonaws.com
  User ec2-user
  IdentityFile ~/.ssh/yourkey.pem

Host 54.252.146.85
  ProxyCommand nc -X connect -x proxyserver:8080 %h %p
  User ec2-user
  IdentityFile ~/.ssh/yourkey.pem

With that, you can connect with its IP address in office

ssh 54.252.146.85

And connect with its dns name at home

ssh ec2-54-252-146-85.ap-southeast-2.compute.amazonaws.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment