What Port Does SSH Use?

SSH stands for Secure Shell support for transferring data between server and client. It is quite useful to remotely connect with operating systems via SSH services and communicate with them. These services are executed through specific SSH ports, which must be configured at both ends, i.e., Client and Server. In this Linux guide, we will provide the methods to check which port SSH uses. The content of this guide is as below:

Let’s start with the guide.

Method 1: Use the “getent” command to Know the SSH Port

In Linux, the “getent” command extracts the details from several files by specifying the name of the service. In the case of SSH, it is executed as follows:

$ getent services ssh

The output shows that “ssh” is used at port 22 through the TCP (Transmission Control Protocol).

Method 2: Use the “systemctl” Command to Know the SSH Port

OpenSSH is a networking utility that relies on the ssh protocol. In Linux, the “systemctl” utility provides support to manage the services. To check the SSH port, you can use the “systemctl” utility to check the status of the SSH service as follows:

$ sudo systemctl status ssh

The output shows details of “ssh services” by displaying the “Tasks”, “Memory”, “CPU” and “Port” information. The port number is highlighted in the screenshot, i.e., 22.

Method 3: Using Configuration File to Display the SSH Port

Another method can also be adapted to check the SSH Port through the “sshd_config” file.

Additionally, users can modify the port number in the “Nano Editor”. To display the SSH Port, execute the below script:

$ sudo nano /etc/ssh/sshd_config

After executing the script, it navigates to the “sshd_config” configuration file on which you can verify the SSH Port number.

Bonus Tip: How to Configure Port 22 For SSH on Linux?

The firewall is the key component to allow/disallow connections over a specific port. To allow connections, the port must be configured properly. If you want to configure port 22 for SSH on Linux, click here to read our detailed article on configuring SSH.

That’s all from this guide.

Conclusion

In Linux systems, SSH uses Port 22, which can be visualized through the “getent” command, “systemctl” command, and “sshd_config” file. The “systemctl” command requires the service name “ssh”, and the “systemctl” command acquires the “status” utility for displaying network information. Port 22 is useful to provide a secure channel in an unsecured environment between the client and server. This guide has covered all aspects of knowing the SSH Port in a Linux system.