I want to change the default SSH port 22 to a different port. Whenever I log in to my server with SSH as root user I can see there are more than 2000+ login fail attempts. So I am thinking of changing the default port of SSH as a countermeasure. Can someone provide clear steps or instructions on how to do this safely?
3. Find and Change the Port Number:
Within the config file, find the below line
#Port 22
Uncomment the line (remove the # ) and change the port number to your desired value. For security reasons, it’s best to choose a port number between 1024 and 49151 that is not commonly used.
Port 4920
4. Save and Exit 5. Restart SSH Service:
systemctl restart sshd
Or
sudo systemctl restart sshd
6. Firewall Configuration (if needed):
If you are using a firewall (like firewalld), ensure that the new SSH port is allowed through.
7. Testing:
Before you close your current SSH session, open a new terminal or SSH client and try connecting to your server using the new port. If you can connect without any issue then you can safely close your SSH sessions.