Recently, I encountered the problem of failing to access my EC2 cloud instance on AWS at my public library. It didn’t take me long to realize the library was blocking SSH connections on port 22 to my instance, which failed to establish the connection. Fortunately, I was able change SSH to listen on port 443 (SSL) instead of 22 (SSH) and tunnel through that.

Enabling SSH on 443 on a New Ec2 Instance:

On a new instance, the process is quite trivial. There are two things you need to do. First, head over to the AWS EC2 portal and launch a new instance.

Once you’re there, you’ll go through the standard process of setting up a new instance to your liking (I’m choosing the free tier instance type)

Choose your instance type
Add user-data script

Step 3 is key, because now we an add a custom user-data script that will allow us to modify our port that listens on SSH at boot-time of our new instance.

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

Great, now we have our instance configured to listen to SSH connections over HTTPS. The final thing we need to do is modify the security group to allow incoming connections to 443.

Go ahead and add a new rule to allow incoming connections on HTTPS type like so:

That’s it! Now to connect, you can do the following:

ssh ec2-user@IP-ADDRESS-TO-INSTANCE -i ec2keypair.pem -p 443

Don’t forget to chmod 400 the pem file. Happy hacking!

LEAVE A REPLY

Please enter your comment!
Please enter your name here