I am not able to access Amazon EC2 instance via ssh as i am behind a firewall. So, i thought of running ssh on port other than 22, like 80 or 443.
I tried starting Amazon EC2 instance via Web Management Console with following 'user data':
#!/bin/bash -ex
perl -pi -e 's/^#?Port 22$/Port 80/' /etc/ssh/sshd_config
service sshd restart || service ssh restart
The idea being that the above script would execute on instance startup and switch ssh from port 22 to port 80. (Ref: http://alestic.com/2010/12/ec2-ssh-port-80)
But ssh is still not accessible on port 80. Apparently 'user data' script is not being executed on start up?
I can 'only' start stop instances via Web Management Console, not from command-line (being behind firewall)
Any ideas?
The amazon firewall blocks all ports other than 22. You first have to enable port 80/443/whatever.
HOWTO: Go to "security groups" -> click on the group you chose for your instance, then on the "Inbound" tab.
There you can add your ports.
EDIT: If by chance you also installed apache or some other webserver, port 80 will be used and cannot be used by sshd. I do not know which operating system is installed on your server, but maybe some webserver is already included?
To connect to an AWS instance through ssh from a port different than default 22:
In your instance:
#!/bin/bash -ex perl -pi -e 's/^#?Port 22$/Port 443/' /etc/ssh/sshd_config service sshd restart || service ssh restart
Please note that this only works if you are launching a new instance:
/etc/ssh/sshd_config
file adding/changingPort 22
to the port that you want (i.e:Port 443
) to connect through ssh and then doservice ssh restart
and you should be done.Note: I did this with an Ubuntu instance, with another Linux instances may be slightly different.