SSH to EC2 instance from behind firewall

Well, this is a short post for those who would like to start an EC2 instance with different SSH ports to access from behind a corporate firewall.

First you must download and install CLI tools from Amazon to manage EC2 resources. After installing CLI tools, create a user data script as follow_

#!/bin/bash -ex
perl -pi -e 's/^#?Port 22$/Port 443/' /etc/ssh/sshd_config
service sshd restart || service ssh restart

After that, run ec2-run-instances command from command line as follow_

ec2-run-instances --key my-aws-keypair --region us-west-2 --instance-type t1.micro --user-data-file user-data-script-file.txt ami-70f96e40

You might want to change the above command with your own parameter set for keypair file, region, instance type etc. Please refer to manual for Amazon CLI tools for more details.

Go to Amazon web console to check your instance is getting started. Finally change security group to allow port 443 as inbound rule.

Now you can ssh into your ect instance with custom port.

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 )

Facebook photo

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

Connecting to %s