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_config

To see the live port that the SSH daemon is listening on, use the ss command:

sudo ss -tulpn | grep sshd

Why 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:

  1. Open the SSH configuration file using a text editor with administrative privileges:

    sudo nano /etc/ssh/sshd_config
  2. Locate the line that says #Port 22 or Port 22.

  3. Remove the # symbol (if present) to uncomment the line, and change 22 to your desired port number (for example, 2222).

  4. Save the file and exit the editor (in Nano, press Ctrl+O, Enter, then Ctrl+X).

  5. 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/tcp
  6. Restart 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.