How do I change my server's port?

Why should I change my server’s SSH port?

The default SSH port is 22. Changing the port can reduce automated scanning attempts on your server. However, changing the port alone does not fully protect your server.

For better security, we recommend combining this with additional measures such as:

  • Using SSH key authentication
  • Disabling password-based login
  • Restricting access using a firewall
  • Allowing SSH access only from trusted IP addresses

Changing the SSH port can help reduce automated login attempts, but it should be considered an additional security measure, not a replacement for proper server security.


Before you begin

Before changing your SSH port, make sure to:

  • Choose a port number between 1024 and 65535.
  • Allow the new port in your firewall before restarting the SSH service.
  • Keep your current SSH session open until you confirm the new port works.

This prevents accidentally locking yourself out of your server.


How do I change the SSH port on a Linux server?

  1. Connect to your server via SSH. (See How do I set up an SSH connection?)
  2. Open the SSH configuration file:
  3. sudo nano /etc/ssh/sshd_config

  4. Find the following line: Port 22
  5. Replace 22 with your desired port (between 1024 and 65535).
  6. Example:

    Port 2222

  7. Save the file and exit the editor.
  8. Allow the new port in your firewall.
  9. Example using UFW (Ubuntu / Debian):

    sudo ufw allow 2222/tcp

  10. Restart the SSH service:
  11. sudo systemctl restart ssh

  12. Connect using the new port:
  13. ssh -p 2222 username@SERVER_IP


How do I change the RDP port on a Windows server?

Windows servers typically use Remote Desktop Protocol (RDP) on port 3389. You can change this port in the Windows Registry.

  1. Open the Windows search bar and type:
  2. regedit

  3. Open the Registry Editor.
  4. Navigate to the following path:
  5. HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp

  6. Find the entry named PortNumber.
  7. Right-click it and select Modify.
  8. Select Decimal and enter your new port number.
  9. Click OK.
  10. Restart the server for the changes to take effect.

Important: After changing the port, allow the new port in your Windows Firewall under:

Inbound Rules → New Rule → Port

When connecting via Remote Desktop, specify the port after the IP address:

SERVER_IP:PORT

Example:

73.xxx.xxx.xxx:4567


Summary

  • The default SSH port is 22.
  • Changing the port can reduce automated scans but is not a complete security solution.
  • Always allow the new port in your firewall before restarting SSH.
  • Use additional security measures such as SSH keys and firewall rules.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article

Can’t find what you’re looking for?