Systemd Commands Cheat Sheet: Application Management Using Systemctl Commands
Systemd Commands Cheat Sheet: Application Management Using Systemctl Commands
This cheat sheet presents command-line executables that are used for working with systemd. The systemd service runs on Linux to consolidate service
con guration and application behavior. systemd is found in Red Hat Enterprise Linux as well as other Linux distributions.
systemctl is the application that interacts with systemd from the command line. This cheat sheet demonstrates how to use various systemctl
subcommands to control the behavior of particular services running on a computer. The journalctl command, which displays information about
systemd activities from its logs, is also introduced.
The subcommands in this section control the behavior of particular applications, usually services (daemons) that run in the background.
systemctl enable
Enables a service. Enabling a service causes the system to start the service upon reboot or whenever a computer starts up. The enable subcommand
does not start the particular service immediately. To start a service immediately using systemctl, use the systemctl start command, described later.
Example:
The systemctl enable command in this example con gures the system to invoke the sshd secure shell service at system startup. This command can be
useful to ensure that users can securely log in from remote systems at any time when the local system is running.
The systemctl is-enabled command that follows veri es that the sshd services is enabled.
The systemctl enable command requires administrator permissions to execute. The command can be run as a subcommand to sudo. If sudo is not
used, systemctl enable prompts for the administrator password. Calling systemctl is-enabled does not require administrator permissions.
$ sudo systemctl enable sshd
systemctl restart
Restarts a service.
The systemctl restart command requires administrator permissions to execute. The command can be run as a subcommand to sudo. If sudo is not
used, systemctl restart prompts for the administrator password.
Example:
The systemctl restart command in this example restarts the httpd web server. This command can be useful after making con guration changes to the
web server, so that the changes take e ect for subsequent incoming requests.
$ sudo systemctl restart httpd
systemctl start
Starts a service.
The systemctl start command requires administrator permissions to execute. The command can be run as a subcommand to sudo. If sudo is not used,
systemctl start prompts for the administrator password.
Example:
The systemctl start command in this example starts the httpd web server. This can be useful to run a service that is not normally running. systemctl
start does not cause the service to restart after the system restarts.
The systemctl status httpd command that follows veri es that the httpd service is running. Calling systemctl status does not require administrator
permissions.
systemctl status
systemctl stop
Stops a service. The systemctl stop command requires administrator permissions to execute. The command can be run as a subcommand to sudo. If
sudo is not used, systemctl stop prompts for the administrator password.
Example:
The systemctl stop command in this example stops the httpd service. This command can be useful if you have to stop a service in order to backup its
data, because you think it is being attacked by a malicious intruder, or for any other reason. The systemctl status httpd command that follows
reports the status.
$ systemctl stop httpd
Note the following line in the status output, which shows that the httpd service is inactive:
Active: inactive (dead) since Mon 2022-01-24 09:56:53 PST; 3s ago
systemctl reboot
Shuts down the computer or virtual machine and immediately restarts it.
Example:
The systemctl reboot command in this example reboots the computer or virtual machine. The -i option ensures a shutdown by ignoring logged-in
users and inhibitors (programs that prevent a shutdown in order to complete some long-running activity).
The systemctl reboot command requires administrator permissions to execute. The command can be run as a subcommand to sudo. If sudo is not
used, systemctl reboot prompts for the administrator password.
sudo systemctl -i reboot
The following shows how to use the journalctl and systemctl programs to get information about services running under systemd.
journalctl
journalctl [options]
journalctl works with systemd’s logging capabilities. systemd stores the system, boot, and kernel log les in a central location in a binary format.
journalctl presents information in the central logging system as human-readable text.
Example:
The journalctl command in this example displays everything stored recently in the log by systemd. The --follow option causes only the most recent
journal entries to be displayed.
$ journalctl --follow
-- Logs begin at Mon 2022-01-24 09:31:39 PST. --
Jan 24 10:01:20 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Jan 24 10:01:20 localhost.localdomain httpd[2813]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using
localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Jan 24 10:01:20 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Jan 24 10:01:20 localhost.localdomain polkitd[876]: Unregistered Authentication Agent for unix-process:2787:124099 (system bus name :1.333,
object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Jan 24 10:01:20 localhost.localdomain httpd[2813]: Server configured, listening on: port 80
Jan 24 10:03:29 localhost.localdomain systemd[1]: Starting dnf makecache...
Jan 24 10:03:34 localhost.localdomain dnf[3052]: Updating Subscription Management repositories.
Jan 24 10:03:35 localhost.localdomain dnf[3052]: Metadata cache refreshed recently.
Jan 24 10:03:35 localhost.localdomain systemd[1]: dnf-makecache.service: Succeeded.
Jan 24 10:03:35 localhost.localdomain systemd[1]: Started dnf makecache.
systemctl list-sockets
7 sockets listed.
Pass --all to see loaded but inactive sockets, too.
systemctl list-units
Lists units that systemd has in memory. A unit refers to any resource that systemd knows how to operate on and manage. Units are listed with the
following columns:
UNIT: Name of the unit
LOAD: Indicates whether the unit is loaded
ACTIVE: Indicates whether the unit is active
SUB: Indicates low-level activation state; for example: mounted or running
Example:
The systemctl list-units command in this example lists units in memory, using the pattern sys-k* to show only units whose names begin with the
characters sys-k.
$ systemctl list-units 'sys-k*'
UNIT LOAD ACTIVE SUB DESCRIPTION
sys-kernel-config.mount loaded active mounted Kernel Configuration File System
sys-kernel-debug.mount loaded active mounted Kernel Debug File System
sys-kernel-tracing.mount loaded active mounted /sys/kernel/tracing
systemctl list-unit-files
Lists a unit’s associated le, which describes how systemd starts and runs a unit. Unit les are listed with the following columns:
UNIT FILE: Name of a the le STATE: State of the le. The state can be static, generated or disabled.
Example:
The systemctl list-unit-files command in this example lists unit les, using the pattern sys-* to show only lenames that begin with the characters sys-.
$ systemctl list-unit-files 'sys-*'
UNIT FILE STATE
sys-fs-fuse-connections.mount static
sys-kernel-config.mount static
sys-kernel-debug.mount static