Unfortunately, securing your VPS against multiple attack vectors is essential. Limiting the overall attack surface and securing ports including the ssh port is just one way to achieve this.
Changing the default SSH port from 22 to a different port enhances security by reducing the risk of brute-force attacks. There is a high value associated with SSH access for criminals because most of the time it will allow root remote access which enables them to abuse the system as they see fit.
When making big changes to critical server systems ensure that you have any necessary backups in place and that your note down the new port. Once this change has been made it can impede your own access if you forget it. The same is true for any applications or services that rely on the default port, ensuring that they’re configured correctly will prevent any negative impacts.
1. Login to your server via SSH, from here enter the /etc/sshd directory with the cd
command.
cd /etc/sshd
2. Moving on from the etc folder use nano
or a text editor of your choice (vim, vi
) to edit the sshd_config file.
nano sshd_config
3. After opening the config file with nano you can search for port configuration using CTRL+W
, 22 and hitting ↵ Enter
.
4. Replace 22 with any port within the range 1025 – 65500. If you are using any specific applications that require SSH access refer to their documentation regarding what port to use. For example IBM Aspera requires 33001.
5. Next using the CTRL+X
keybind you can save these changes in nano.
6. Finally restart the SSH service to apply the changes on AlmaLinux based systems you can use the command blow.
service sshd restart