Ubuntu

How to Do an SSHd Restart

OpenSSH is a suite of techniques for controlling connected machines transmitting information amongst them. You’ll also discover how to adjust a few of the OpenSSH server’s customization options on the Linux machine. Conventional techniques for doing these tasks, like telnet as well as RCP, seem to be unsafe and communicate the passcode in plaintext form. OpenSSH is a server host plus client software that allows for safe, encoded remote control and file transmission, essentially replacing traditional technologies. We will let you know about installing it on our system, stopping and restarting it within Ubuntu 20.04 system.

Let’s get started with implementing sshd restart in the Ubuntu 20.04 Linux system. For this, we need to get started with the terminal shell. It has to be launched through the “Ctrl+Alt+T” shortcut. The terminal will be popped up in a few seconds. There comes the execution of an update instruction in the terminal query area. The update command is used to ensure that our Ubuntu 20.04 system is up to date and refreshed. The “apt” package is here for our help to execute this command appropriately. Now, the system is updated.

Let’s first check the available version for SSH in our Ubuntu 20.04 system to be installed. The version command is utilized in the query area of the shell, i.e., “-V” fag with the shh keyword. The version is displayed in the output area.

We need to add the ssh package to our system using the “apt-get” package command. This ssh package is an openssh-server application required to be configured on our end. You can also install the openssh-client application. But, we are only elaborating the server application installation for openssh here. Therefore the below-shown installation command is used.

The openssh-server application package is started to download. The download process asked for your affirmation to continue processing and installing it on our system. We have to add the alphabet “Y” to continue it. We did the same as we mentioned and tapped Enter. It started installing the openssh-server package on our system until it was done.

The installation will be completed within a few minutes, as shown below. Now, we are ready to go along with the enabling and use of sshd.

Now, you have to update some of the configurations for openssh-server in its configuration file. To open its configuration file, we need to use the sudo privileges and the “sshd” keyword. This command contains the path to the sshd configuration file held in our system’s “/etc/ssh/” folder. The “-f” flag forces the system to open the file without hesitation.

After using the above sshd_config command to open the configuration file, we will encounter the opening of a file within the terminal. It will show us many of the settings already configured in it. First, you have to go to the “Port” option and set it to 2222, as shown in the image below. This configuration setting can be found below the “include” path line.

After the port configuration, you need to update the banner line. You have to add the “/etc/issue.net” path in front of it to ensure that our SSH server must show the path file contents. This line may be found as commented. Update it after removing the # sign.

After updating all the configurations and settings of sshd using its configuration file, we are now ready to enable our openssh server. The systemctl command is quite well-known amongst Linux users when it comes to enabling, disabling, stop and starting any service. So, we have been using the systemctl command here first to enable the ssh server. The “enable” word is the key here, along with the “ssh” keyword. It will enable the ssh server by synchronizing the sysv script. The output for this command has been shown below within the image.

Now it is enabled and ready to be started. So, the systemctl command will be utilized once again to start the ssh service. After the start of ssh service, we have to check whether it is appropriately active and running. The same systemctl has been utilized once again for this. There is only a single word difference in both the commands, i.e., start and status. The output shows the Openssh Service is currently active and running properly.

To check the status of ssh service, you can also use the keyword sshd instead of ssh as below.

Let’s just deactivate its service and prevent it from working correctly. So, the same systemctl command will be utilized with the “stop” keyword along with the sshd server name.

After that, we need to disable this service from our system using the disable keyword in the systemctl sshd command. You can see that the service files are being removed from the system.

After checking the sshd service status utilizing the systemctl command in the terminal, we have found that the service is now inactive and dead. The output is shown below.

We have to utilize the same systemctl command with the “restart” keyword to restart the ssh service. The sudo privileges are essential in the command. After restarting, this service needs to be enabled using the systemctl command and the keyword “enable” in it. The service will be enabled by the synchronization as shown in the output.

Now, we have to validate the status of the sshd service once again. The same systemctl command comes here for our help. The “status” keyword is utilized in the command and the “sshd” service name. The output for this command shows that the sshd service is restarted.

Conclusion

We have completed this guide for the implementation of sshd service restart. We have started it by installing the openssh-server and enabling it on the Ubuntu 20.04 system. After that, we have seen how to stop and disable it. At last, we have shown how to restart this service in Ubuntu 20.04 system.

About the author

Saeed Raza

Hello geeks! I am here to guide you about your tech-related issues. My expertise revolves around Linux, Databases & Programming. Additionally, I am practicing law in Pakistan. Cheers to all of you.