Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codspire/61ecaf8b9f4038b635fbb83c781df499 to your computer and use it in GitHub Desktop.
Save codspire/61ecaf8b9f4038b635fbb83c781df499 to your computer and use it in GitHub Desktop.

Access EC2 from behind the firewall that block port 22

If your corporate firewall does not allow ssh to EC2 instances due to blocked port 22 you can follow below workaround temporarily to ssh to EC2 instances.

Essentially you need to change the sshd configuration to use port 80 which is typically open in most firewalls to allow http access.

Step 1: Launch a new EC2 instance

Step 2: On "3. Configure Instance" step, expand the "Advanced Details" section and put the below code

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

Step 3: Launch the instance

Step 4: After successful startup, use the below ssh command to connect to this instance

ssh -p 80 -i "YOURKEYPAIR.pem" ec2-user@IPADDRESS

Inspired by: https://alestic.com/2010/12/ec2-ssh-port-80/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment