Use Systemd to Manage Services, Run Levels and Logs on Linux

Systemd is not only a service manager but also a system manager for Linux. It’s designed to be backward compatible with SysV init scripts and used by many popular Linux distributions like Debian 8+, Ubuntu 15.04+, Fedora, Redhat 7+ /CentOS 7+, Arch Linux, OpenSUSE. So it will be very helpful to know how to use systemd.

This tutorial shows you some basic commands that will be useful to manage services, run levels, and logs. First, you might want to know the systemd version on your Linux distribution, run

systemd --version


systemctl --version

systemd check version

Managing Services

Systemd can help you start, stop, restart services and also allows you to auto-start services at boot time.

To list active systemd services, run

systemctl list-units --type service

Check the status of a specific service, for example, SSH daemon.

systemctl status ssh

To start a service, use the start subcommand:

sudo systemctl start ssh

Check if it’s active (running)

systemctl is-active ssh

Enable a service to autostart at boot time

sudo systemctl enable ssh

Check if it’s enabled

systemctl is-enabled ssh

Prevent a service from starting up at boot time

sudo systemctl disable ssh

Stop a service

sudo systemctl stop ssh

To prevent a service from starting manually, use the mask subcommand

sudo systemctl mask ssh

Masked services can’t be started with systemctl start command until it’s unmasked.

sudo systemctl unmask ssh

Managing Run Levels

The concept of run levels is replaced by targets in systemd. The is equivalent to run level 3 and the is equivalent to run level 5. You can still use the runlevel command to show the current run level.


Use the following command to check the status of the default target, which by default is usually the graphical target (run level 5).

systemctl status

systemd default boot target

You use systemctl isolate command to change target. For example, change to the (run level 3):

sudo systemctl isolate

And to change back to graphical target (run level 5):

sudo systemctl isolate

To set as the default target, use the following command:

sudo systemctl set-default

This command creates a symbolic link.

systemd default target

If you reboot now, you will be taken to multi-user target.


To list active targets, run

systemctl list-units --type target

Managing Logs

The systemd software suite includes a journalctl utility which can be used to manage logs on Linux. Linux traditionally saves logs under /var/log/ directory. On a Linux distribution with systemd, you may not be able to find logs such as postfix mail logs (/var/log/mail.log) in that directory.

You can view recent logs with the following command. You can press F key to jump to the next page and press B key to going back to the previous page. Press Q to quit.

sudo journalctl

Use grep to search for logs related to your search term

sudo journalctl | grep <search term>

View logs since the current boot

sudo journalctl -b

View logs since the previous boot

sudo journalctl -b -1

Here’s a little trick to show logs being generated in real time.

sudo journalctl -f

journalctl examples

Show logs of a unit, for instance, the ssh service unit.

sudo journalctl -u ssh

To view Postfix logs, run

sudo journalctl -u postfix

Conflicting Services

When two services shouldn’t run at the same time, you can use the Conflicts parameter. For example, I always use a VPN on my Ubuntu desktop computer. It’s a self-hosted VPN running on a Vultr VPS. Then I sometimes use Transmission to download torrents. When I start Transmission, I must close the VPN connection, because Vultr will shut down your account if you use their servers to download torrents (I mean downloading copyright-infringing materials via BitTorrent).

I can edit the transmission-daemon.service.

sudo nano /lib/systemd/system/transmission-daemon.service

Add the following line in the [Unit] section.


systemd conflicting services

Save and close the file. Then reload systemd for the changes to take effect.

sudo systemctl daemon-reload

openconnect.service is the service that starts VPN connection on my computer. Now if I start transmission-daemon.service, openconnect.service will be automatically shut down, and vice versa.


If you want service B to start when service A starts, you can use the Wants parameter to make it happen. In the [Unit] section of a systemd .service file, add a line like this:

Wants = name.service

Run /etc/rc.local Scripts

If you are running a Linux distro that uses Systemd, you may find that your commands in /etc/rc.local file would not run at system boot time. The following tutorial explains how to enable /etc/rc.local script to run on system startup.

Wrapping Up

That’s it! Subscribe to our free newsletter to get the latest Linux tutorials. You can also follow us on Twitter or like our Facebook page.

Rate this tutorial
[Total: 4 Average: 5]

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community ( for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded.