How to Restart the SSH Service?

SSH is an open-source client-server architecture that enables encrypted system connection. It is also known as the practical implementation of SSH protocol. This connection can be utilized to transfer files and access the terminal. 

It is mainly used for the encrypted connection that securely transfers information between the server and the client. Sometimes the SSH service slows down or may generate an operational error. So restarting it in such scenarios and performing the task smoothly is recommended. 

This guide lists down the possible ways to restart SSH Service on Linux with the following highlights:

Method 1: Using the “systemctl” Command 

The “systemctl” command-line tool manages the “systemd” initialization system and service manager. It allows the user to interact with the services using options such as “start”, “enable”, “stop”, “disable”, and view.

Restart SSH Service

Execute the “systemctl” command followed by the “restart” options and the superuser privileges i.e “sudo” to restart the “SSH” service:

$ sudo systemctl restart ssh

The error-free output confirms that “SSH” service is restarted.

Check SSH Service  Status

If the user wants to check the current status of the “SSH” service, then use the “status” with the “systemctl” command:

$ sudo systemctl status ssh

The SSH service is now in an “active (running)” state.

Method 2: Using the “service” Command 

The other tool is the “service” command utility utilized to execute a SystemV init script in the in /etc/init.d directory. It can also start, stop, restart, reload, and enable the services like the systemctl command.

Restart SSH Service

Type the “restart” flag alongside the “sudo” and “service” commands for restarting the “ssh” service in the following way:

$ sudo service ssh restart

It provides the same output as the “systemctl” command.

Method 3: Using “/etc/init.d” Directory

 The “etc/init.d” is the directory that contains the start and stop scripts to manage the start, stop, restart, and reload process of the service at boot time. It requires the superuser privileges to access and control the script using the terminal manually.

Restart SSH Service

Specify the name of the “SSH” service with the “restart” control command in the terminal to restart it:

$ sudo /etc/init.d/ssh restart

Conclusion 

Linux offers the “systemctl” and “service” command line tools to restart the “SSH” service instantly. It can also be restarted by accessing the “/etc/init.d” directory using the “restart” command. All commands use the “sudo” i.e, root user access if the normal user is logged in. This guide has demonstrated all possible ways to restart the SSH Service.