← Volver al blog

How to Change SSH Port in Linux

  • Xernode
  • 1 min de lectura
  • 19 de marzo de 2026
Linux ssh firewall port security 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

  1. Open the SSH configuration file:
    • sudo nano /etc/ssh/sshd_config
  2. Find the line:n
    • #Port 22
    • Remove the # and change 22 to your desired port (e.g., 2222):
    • Port 2222
  3. Save and exit the editor.
  4. 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
  5. Restart the SSH service:
    • sudo systemctl restart sshd
  6. 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

Related Guides