Why Change the Default SSH Port?
Changing the default SSH port is a common security practice that helps protect your server from automated attacks and brute-force scans. Since most bots target port 22, moving SSH to a different port can significantly reduce unwanted login attempts.
Changing SSH Port on Linux (Ubuntu, Debian, CentOS, RHEL)
- Connect to Your Server
- Use your preferred SSH client to connect using the current port (default: 22).
- Edit the SSH Configuration File
- Open the SSH configuration file:
/etc/ssh/sshd_config
- Open the SSH configuration file:
- Locate the “Port” Directive
- Find the line that begins with
Port.
- Find the line that begins with
- Change the Port Number
- Replace the current port number with your desired value:
Port 2222 - Save and Close
- Save the file and exit the editor.
- Restart SSH Service
sudo service ssh restart # Ubuntu/Debian sudo systemctl restart ssh # CentOS/RHEL
Changing SSH Port on Windows (OpenSSH Server)
- Connect to Your Server
- Use an SSH client like PuTTY on port 22.
- Navigate to the Configuration Directory
C:\ProgramData\ssh
- Edit sshd_config
- Open the file in a text editor.
- Modify the Port Value
Port 2222 - Restart SSH Server
Restart-Service sshd
Firewall Considerations
After changing the SSH port, update your firewall rules to allow the new port:
- UFW (Ubuntu)
sudo ufw allow 2222/tcp- firewalld (CentOS/RHEL)
sudo firewall-cmd --add-port=2222/tcp --permanent
sudo firewall-cmd --reloadConnecting Using the New SSH Port
After updates, connect using:
ssh -p 2222 username@your_server_ipReplace 2222 with the new port number.
If you manage production environments or high-traffic workloads, it’s a good idea to combine SSH hardening with reliable infrastructure. You can explore our dedicated server plans for secure and high-performance hosting options.
Frequently Asked Questions
Why should I change the default SSH port?
Changing the default SSH port from 22 to a custom port helps reduce automated scans and brute-force attacks that target common ports.
Does changing the SSH port make my server secure?
It improves security by reducing noise, but it is not enough on its own. You should also use SSH keys, disable root login where possible, and apply a firewall.
What is a good SSH port number?
Use a non-standard port above 1024 that is not used by other services. Avoid commonly scanned ports and document the chosen port clearly for your team.
I changed the SSH port and can’t connect. What should I do?
First, check firewall rules and confirm that the SSH service is listening on the new port. If remote access is completely lost, use your hosting provider’s console or IPMI access to revert the configuration.





