Debian

Stop, Start and Restart Services on Debian

This tutorial explains how to start, stop and restart services in Debian 11 Bullseye using both systemctl and service commands.

Services on Linux Debian 11

A service is a program running in the background to be used when needed. Apache, ssh, Nginx or Mysql are some of the most known services. On Debian, including Debian 11 Bullseye, services are managed with Systemd, the replacement of System V to initialize the system and its components, including services.

Start, Stop and Restart Services on Debian 11 Using Systemd

The Systemd is a suite to manage Linux services and daemons (the last “d” is because of Unix daemons). The systemctl command allows to start, stop, restart and check services status. Its aim is to unify the configuration and behaviour for all Linux distributions replacing the old Unix SystemV and BSD init systems.

This tutorial section shows execution examples of the actions described in the following table.

ACTION COMMAND
Check service status sudo systemctl status <ServiceName>
Stop a service sudo systemctl stop <ServiceName>
Start a service sudo systemctl start <ServiceName>
Restart a service sudo systemctl restart <ServiceName>

As shown in the previous table, the syntax to check the status of a service using Systemd is the following:

systemctl status <Service-Name>

Therefore, to check the status of the ssh service you can run the following command.

sudo systemctl status ssh

As you can see in the screenshot above, the ssh service is active and properly running.

To stop a service, the syntax is similar, just replace the status option with the action you want to execute, in this case the action is to stop.

For example, to stop the ssh service run the command below.

sudo systemctl stop ssh

As you can see, after stopping the service and checking the status, the ssh service now appears as inactive (dead).

To start a service, just replace stop with start, as shown in the screenshot below. To start the ssh service, run:

sudo systemctl start ssh

As you can see, the service is running again.

To restart a service, the option you need to type is restart. The following command is used to restart the ssh service.

sudo systemctl restart ssh

That’s how services are restarted using Systemd.

You can get additional information on Systemd at https://systemd.io/.

Stop, Start and Restart Services on Debian 11 Using the Service Command

The service command is used to manage services under the /etc/init.d directory despite some distributions redirecting the command to the previously explained systemctl command.

This command can also be used to stop, start and restart services following the syntax described in the table below.

ACTION COMMAND
Check service status sudo service <ServiceName> status
Stop a service sudo service <ServiceName> stop
Start a service sudo service <ServiceName> start
Restart a service sudo service <ServiceName> restart

This section shows examples of application of the commands described in the above table.

To check the status of a service (ssh in this case) using the service command, use the syntax shown below. Replace “ssh” with the service you want to check.

sudo service ssh status

As you can see, the ssh service is active and running properly.

The command shown in the screenshot below is used to stop services. Run it to stop the ssh service, or replace “ssh” with the service you want to stop.

sudo service ssh stop

As you can see, after running service ssh stop, ssh is now inactive.

To start the ssh service back, use the following syntax. Remember to replace “ssh” with the service you want to load.

sudo service ssh start

Finally, to restart services using the service command, use the syntax below.

sudo service ssh restart

As you can see, the service runs properly.

The following command can be used to reload a service configuration without interrupting the service itself.

sudo service ssh reload

You can get more information on the service command at https://linux.die.net/man/8/service.

Conclusion

Services are an essential component of any device. Managing services properly is a must for any Linux level user. As you could see with this tutorial, managing services is pretty simple and can be done through different methods. Always keep in mind the recommended method to deal with services in Linux is the systemctl command explained in the first section of this article. Other methods (like dealing directly with the /etc/init.d directory) are considered obsolete, and were removed from the first version of this tutorial. All commands explained in this tutorial are useful to stop,start, restart and check service status, but there are additional functions you can learn on their respective man pages.

Thank you for reading this tutorial explaining how to stop, start and restart services on Debian 11. Keep following us for additional Linux tips and tutorials.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.