
{{ $('Map tags to IDs').item.json.title }}
How to Change SSH Port
Changing the default SSH port (22) to a custom port can enhance the security of your server by reducing the likelihood of automated attacks. This tutorial will guide you through the steps required to change the SSH port in Linux.
1. Accessing the SSH Configuration File
To change the SSH port, you first need to edit the SSH configuration file. Open a terminal and run the following command:
sudo nano /etc/ssh/sshd_config
This command opens the SSH configuration file in the nano text editor.
2. Modifying the SSH Port
In the sshd_config
file, look for the line that specifies the port:
#Port 22
Uncomment this line (remove the #
) and change 22
to your desired port number, for example:
Port 2222
Choose a port number above 1024 to avoid conflicts with reserved ports.
3. Allowing the New Port Through the Firewall
If you have a firewall enabled (like UFW or firewalld), you will need to allow the new port:
- For UFW: Run:
sudo ufw allow 2222/tcp
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
Replace 2222
with your chosen port number.
4. Restarting the SSH Service
To apply the changes, restart the SSH service:
sudo systemctl restart sshd
This command will make SSH listen on the new port.
5. Testing the New Port
Before closing your current SSH session, open a new terminal and test the new SSH port to ensure it works:
ssh -p 2222 username@your_server_ip
Replace username
with your actual username and your_server_ip
with the server’s IP address. If successful, you can close the original session.
6. Security Considerations
Always ensure you keep the default port open until you confirm that the new port works to avoid being locked out. Afterward, you can close the old port to strengthen your server’s security.
7. Conclusion
By following this tutorial, you have successfully changed the SSH port of your server in Linux. Changing the SSH port helps secure your server against unauthorized access and automated attacks. Continue to explore additional security best practices to keep your server environment safe!