How to check if an SSH server is running in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check if an SSH server is running on a Linux system. You will use the systemctl status ssh command to verify the service's running state, the ss -tuln command to check if the SSH port is open and listening, and the cat /etc/ssh/sshd_config command to inspect the SSH server configuration file. These steps are fundamental for troubleshooting and verifying SSH server functionality.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/SystemInformationandMonitoringGroup(["System Information and Monitoring"]) linux(("Linux")) -.-> linux/RemoteAccessandNetworkingGroup(["Remote Access and Networking"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/SystemInformationandMonitoringGroup -.-> linux/service("Service Managing") linux/RemoteAccessandNetworkingGroup -.-> linux/netstat("Network Monitoring") subgraph Lab Skills linux/cat -.-> lab-558785{{"How to check if an SSH server is running in Linux"}} linux/service -.-> lab-558785{{"How to check if an SSH server is running in Linux"}} linux/netstat -.-> lab-558785{{"How to check if an SSH server is running in Linux"}} end

Check SSH service with systemctl status ssh

In this step, you will learn how to check the status of the SSH service on your Linux system. SSH (Secure Shell) is a protocol used to securely connect to a remote computer. It's a fundamental tool for system administration and development.

In Linux, services like SSH are often managed by systemd, a system and service manager. The systemctl command is used to interact with systemd.

To check the status of the SSH service, you will use the systemctl status command followed by the service name, which is ssh.

Open your terminal if it's not already open. You can find the Xfce Terminal icon on the left side of your desktop.

Type the following command into the terminal and press Enter:

systemctl status ssh

You will see output similar to this:

● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running) since ...
       Docs: man:sshd(8)
             man:ssh(1)
   Main PID: ... (sshd)
      Tasks: 1 (limit: ...)
     Memory: ...
        CPU: ...
     CGroup: /system.slice/ssh.service
             └─... /usr/sbin/sshd -D

...

Let's break down the important parts of the output:

  • ● ssh.service: This is the name of the service.
  • Loaded: loaded (...): Indicates that the service configuration file has been loaded by systemd.
  • Active: active (running): This is the most important part. It tells you that the SSH service is currently running. If it were stopped, it would show something like inactive (dead).
  • since ...: Shows when the service started.
  • Main PID: ... (sshd): The Process ID of the main SSH daemon process (sshd).

This command is essential for troubleshooting network connectivity issues or verifying that a service is running as expected.

Click Continue to proceed to the next step.

Verify SSH port with ss -tuln

In this step, you will learn how to verify which network ports are open and listening on your system. This is crucial for understanding how services like SSH are accessible.

The ss command is a utility to investigate sockets. Sockets are endpoints for sending and receiving data across a network. We will use ss with several options to filter the output:

  • -t: Display TCP sockets. SSH uses the TCP protocol.
  • -u: Display UDP sockets.
  • -l: Display listening sockets. These are sockets that are waiting for incoming connections.
  • -n: Do not resolve service names. This shows port numbers instead of names like ssh or http.

Combine these options to see all listening TCP and UDP ports with their numerical values.

Type the following command into your terminal and press Enter:

ss -tuln

You will see output listing various listening ports. Look for the line related to SSH, which typically listens on port 22. The output might look something like this (the exact order and other ports may vary):

Netid  State   Recv-Q  Send-Q   Local Address:Port   Peer Address:Port
tcp    LISTEN  0       128            0.0.0.0:22          0.0.0.0:*
tcp    LISTEN  0       128               [::]:22             [::]:*
udp    UNCONN  0       0              127.0.0.53%lo:53          0.0.0.0:*
udp    UNCONN  0       0                    0.0.0.0:68          0.0.0.0:*

In this output:

  • Netid: The network protocol (tcp or udp).
  • State: The state of the socket (LISTEN means it's waiting for connections).
  • Local Address:Port: The local IP address and port number the service is listening on. 0.0.0.0 means it's listening on all available IPv4 addresses, and [::] means it's listening on all available IPv6 addresses.
  • Peer Address:Port: The address and port of the remote connection (for listening sockets, this is *).

You should see lines indicating that TCP port 22 is in the LISTEN state. This confirms that the SSH service is running and ready to accept connections on the standard SSH port.

Understanding how to check open ports is a fundamental skill for network troubleshooting and security.

Click Continue to move to the next step.

Inspect SSH config with cat /etc/ssh/sshd_config

In this final step, you will examine the main configuration file for the SSH server. This file contains settings that control how the SSH service behaves, such as which port it listens on, which users are allowed to connect, and security options.

The configuration file for the SSH daemon (sshd) is typically located at /etc/ssh/sshd_config. The /etc directory is where system configuration files are stored.

To view the contents of this file, you can use the cat command. cat is a simple command that reads files sequentially and prints them to the standard output (your terminal).

Type the following command into your terminal and press Enter:

cat /etc/ssh/sshd_config

You will see the entire content of the sshd_config file printed in your terminal. The output will contain many lines, some starting with # (which are comments and are ignored by the system) and others defining configuration options.

Look for lines that are not commented out (do not start with #). Some important directives you might see include:

  • Port 22: This specifies the port the SSH server listens on. By default, it's 22.
  • ListenAddress 0.0.0.0: Specifies the IPv4 address the server listens on.
  • ListenAddress ::: Specifies the IPv6 address the server listens on.
  • PermitRootLogin prohibit-password: Controls whether the root user can log in directly via SSH.
  • PasswordAuthentication yes: Controls whether password authentication is allowed.
## This is the sshd server system configuration file.
## See sshd_config(5) for more information.

## The systemd service file for sshd uses EnvironmentFile to load
## the SSHD_CONFIG environment variable, setting this to /etc/ssh/sshd_config.
## ...

Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

## Ciphers and keying
#...

## Authentication:
LoginGraceTime 2m
PermitRootLogin prohibit-password
StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

## Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile	.ssh/authorized_keys .ssh/authorized_keys2

#IgnoreRhosts yes
#RhostsRSAAuthentication no
#HostbasedAuthentication no
#...

PasswordAuthentication yes
#PermitEmptyPasswords no

ChallengeResponseAuthentication no

#...

Reading configuration files like this is a key skill for understanding and managing Linux services. While you won't modify the file in this lab, knowing where it is and how to view its contents is very useful.

You have now successfully checked the SSH service status, verified its listening port, and inspected its configuration file. You've gained valuable experience with fundamental Linux commands for service management and network inspection.

Click Continue to complete the lab and see your progress!

Summary

In this lab, you learned how to check if an SSH server is running on a Linux system. You used the systemctl status ssh command to verify the service's active state and understand key details like its loaded status, active state, and process ID. This command is crucial for confirming the SSH service is operational.

You also learned how to verify the SSH port using the ss -tuln command and inspect the SSH configuration file located at /etc/ssh/sshd_config using the cat command. These steps provide further insight into the SSH server's network configuration and settings.