In this guide, we will explain how to change the default SSH port. To make an SSH connection, port 22 is the default port. During the operating system installation process, this port is automatically established.
Altering another port for SSH access can help lower the quantity of brute force attempts.
Please Note:
Verify that the installed programs and services on the server may be setup without a default port before altering it. If not, these services and apps can stop functioning if the default port is changed.
Follow the steps:
- Sign in to the server with administrative privileges.
- Use the ‘vi’ text editor to open the SSH configuration file ‘sshd_config’:
vi /etc/ssh/sshd_config
- Look up the entry. Port 22.
- Choose a port between 1024 and 65536 to replace port 22.
- Conserve the file.
- Give the service a restart:
- Ubuntu
service ssh restart
- CentOS 7
systemctl restart sshd
- To initiate an SSH connection after making this change, run the following command:
ssh root@IP_address_of_the_server -p NewPort
- Ubuntu
Looking to secure your server further? Check out the Steps to Change SSH Port in Red Hat Enterprise Linux