Default SSH Port on Ubuntu Linux
This article provides a quick guide to the default port used by the Secure Shell (SSH) server on Ubuntu Linux. It covers what the default port is, how to verify the active port on your system, and the steps to change it to enhance server security.
The default port used by the SSH server on Ubuntu Linux is port 22. This is the standard port designated by the Internet Assigned Numbers Authority (IANA) for SSH traffic across almost all Linux and Unix-like operating systems. When you install the OpenSSH server on Ubuntu, it automatically listens for incoming connections on this port.
How to Verify Your SSH Port on Ubuntu
If you want to check which port your SSH server is currently using, you can inspect the SSH configuration file or check active network sockets.
To check the configuration file, run the following command in your terminal:
grep -i port /etc/ssh/sshd_configTo see the live port that the SSH daemon is listening on, use the
ss command:
sudo ss -tulpn | grep sshdWhy and How to Change the Default Port
Keeping your SSH server on the default port 22 makes it a constant target for automated bots and brute-force login attempts. Changing the default port to a random high port (between 1024 and 65535) is a common security practice.
To change the default SSH port on Ubuntu:
Open the SSH configuration file using a text editor with administrative privileges:
sudo nano /etc/ssh/sshd_configLocate the line that says
#Port 22orPort 22.Remove the
#symbol (if present) to uncomment the line, and change22to your desired port number (for example,2222).Save the file and exit the editor (in Nano, press
Ctrl+O,Enter, thenCtrl+X).If you are using the Uncomplicated Firewall (UFW), allow the new port and block the old one:
sudo ufw allow 2222/tcp sudo ufw deny 22/tcpRestart the SSH service to apply the changes:
sudo systemctl restart ssh
Once restarted, any new SSH connections to your Ubuntu server must specify the new port number.