In this short tutorial you will learn how to change your SSH port from the default 22 to another port. This is a recommended step during any initial server hardening.
Change your ssh port: #
- Edit your ssh configuration file:
- Find line: #Port 22
- Uncomment the line
- Change 22 to your desired port number
- Save the file
- Restart SSH service
systemctl restart ssh
Check your firewall UFW #
If your firewall is active, it is possible it would be blocking your newly set port. As such add a firewall rule to allow your new port through the firewall:
ufw allow from any to any port 12345 ufw reload
where 12345 is the ssh port you set, or if you have existing firewall rules, it might be a good idea to add your rule on top of all rules to avoid conflicts:
ufw insert 1 allow from any to any port 12345 ufw reload
That should be all. Try and ssh into your server on your new port.