How to Change SSH Port in Linux
Introduction:
Changing the default SSH port in Linux is a simple way to improve your server’s security and reduce brute-force attacks.
Step-by-step Guide
- Open the SSH configuration file:
- sudo nano /etc/ssh/sshd_config
- Find the line:n
- #Port 22
- Remove the # and change 22 to your desired port (e.g., 2222):
- Port 2222
- Save and exit the editor.
- Allow the new port through your firewall:
- For UFW:n
- sudo ufw allow 2222/tcp
- For firewalld:n
- sudo firewall-cmd --permanent --add-port=2222/tcp
- sudo firewall-cmd --reload
- For UFW:n
- Restart the SSH service:
- sudo systemctl restart sshd
- Test the new SSH port in a new terminal:
- ssh -p 2222 user@your_server_ip
Recommendations
- Avoid using common ports like 2222 or 2200; choose a random high port.
- Always keep a backup session open when testing changes.
- Update any firewall or security group rules accordingly.
Call To Action:
Need a secure VPS for Linux? Try our plans now! https://xernode.com/#pricing