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?
- Connect to your server via SSH. (See How do I set up an SSH connection?)
- Open the SSH configuration file:
sudo nano /etc/ssh/sshd_config- Find the following line:
Port 22 - Replace 22 with your desired port (between 1024 and 65535).
Example:
Port 2222- Save the file and exit the editor.
- Allow the new port in your firewall.
Example using UFW (Ubuntu / Debian):
sudo ufw allow 2222/tcp- Restart the SSH service:
sudo systemctl restart ssh- Connect using the new port:
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.
- Open the Windows search bar and type:
regedit- Open the Registry Editor.
- Navigate to the following path:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp- Find the entry named PortNumber.
- Right-click it and select Modify.
- Select Decimal and enter your new port number.
- Click OK.
- 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
Feedback sent
We appreciate your effort and will try to fix the article