The server cannot be reached through the selected SSH port after changing it on the sshd_config
file and enabled on UFW
settings
-
Update all currently installed packages
sudo apt-get update sudo apt-get upgrade
-
Change the SSH port from 22 to 2200
- Use
sudo nano /etc/ssh/sshd_config
and then change Port 22 to Port 2200 , save & quit. - Reload SSH using
sudo service ssh restart
- Use
-
Configure the Uncomplicated Firewall (UFW)
- Configure the Uncomplicated Firewall (UFW) to only allow incoming connections for SSH (port 2200), HTTP (port 80), and NTP (port 123)
sudo ufw allow 2200/tcp sudo ufw allow 80/tcp sudo ufw allow 123/udp sudo ufw enable
⚠️ If you still cannot access the instance after making the changes run the following steps
-
Open the AWS panel on https://lightsail.aws.amazon.com/
-
Click on the instance details, it will redirect you to something like:
https://lightsail.aws.amazon.com/ls/webapp/us-east-1/instances/Ubuntu-512MB-Virginia-1/
-
Now select the
Network
tab -
Click on the
Add another
button on the bottom left -
Select
Custom
on application column,TCP
, and2200
on the following -
Reboot the machine
If you block the SSH port on UFW BEFORE changing the sshd_config
file, you can create a deadlock, which is pretty much irreversible, check some links below to get general help on how to save time recreating the instance
- https://stackoverflow.com/questions/41929267/locked-myself-out-of-ssh-with-ufw-in-ec2-aws <- This one shows how to perform a recovery on AWS instances, so you would not lose all of your work