How to Change the SSH Port on the VPS
This guide explains how to change the default SSH port on your server and update the required firewall settings so that SSH access continues to work.
Follow the steps below exactly as written, and make sure the new SSH port is not already in use on the system.
Keep your current SSH session open until you have successfully connected using the new SSH port. This helps prevent you from being locked out if the SSH configuration or firewall settings are incorrect.
Change the SSH Port
Open the SSH configuration file
Change the port
Find the line that says Port 22 and change it to your desired SSH port. Replace <SSH port Here> with the port number:
Save the file and restart SSH
Save the file, then restart the SSH service:
Connect using the new port
The next time you SSH into your VPS or server, specify the port you set:
Update Your Firewall Configuration
Use the section below that matches the firewall on your system. In the commands, change 22 to the new port you set above, and then run them.
UFW
UFW is used primarily on Ubuntu-based systems.
firewalld
firewalld is primarily used on CentOS 7.
iptables
iptables is commonly used on systems such as CentOS 6 and Debian.

