SSH Port Number: How to Check and Change It in Linux
Learn how SSH port 22 works, check your server's SSH configuration, and change the port using simple Linux commands.
What Is an SSH Port Number?
Secure Shell (SSH) is an encrypted protocol that allows administrators to log in to remote servers, execute commands, and transfer files securely. By default, SSH listens on TCP port 22, unless the server administrator configures a different port.
1. How to Check the SSH Port
To display the effective SSH port configuration, run:
sudo sshd -T | grep '^port'
To check which TCP ports are listening for SSH:
sudo ss -tlnp | grep sshd
2. How to Change the SSH Port
If you want SSH to use a custom port, follow these steps carefully.
Step 1Back Up the Configuration
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
Step 2Edit the SSH Configuration
sudo nano /etc/ssh/sshd_config
Find the existing Port directive. Set it to an available port, for example:
Port 5522
Save the file and exit the editor.
Step 3Allow the Port Through the Firewall
For UFW-based systems:
sudo ufw allow 5522/tcp
For systems using FirewallD:
sudo firewall-cmd --permanent --add-port=5522/tcp
sudo firewall-cmd --reload
Step 4Validate the Configuration
sudo sshd -t
Step 5Restart the SSH Service
Ubuntu and Debian:
sudo systemctl restart ssh
AlmaLinux, Rocky Linux, and CentOS:
sudo systemctl restart sshd
Step 6Connect Using the New Port
ssh -p 5522 username@server_ip
3. Common SSH Connection Problems
Check firewall rules, network connectivity, and provider-level port filtering.
Check whether the SSH service is running and listening on the configured port.
Verify the username, SSH key or other authentication method, and account permissions.
Conclusion
SSH port 22 is the default for secure remote Linux administration. You can check or change the port using standard Linux commands, provided the SSH configuration and firewall rules are updated correctly.