Install
# Most modern distros ship systemd + systemctl by default. # If you truly need to install it (rare), it is typically the "systemd" package: # RHEL / Alma / Rocky sudo dnf install systemd # Debian / Ubuntu sudo apt install systemd # openSUSE sudo zypper install systemd # Arch sudo pacman -S systemd
What it does
systemctl is the front-end command for controlling systemd, the init system and service manager on many Linux distributions. It lets you start/stop/restart services, enable/disable them at boot, and inspect unit status and logs.
How it works (mechanical)
- Talks to the running systemd manager (PID 1) over D-Bus / systemd’s control interface.
- Reads unit files from standard paths (e.g., /usr/lib/systemd/system, /etc/systemd/system).
- “Runtime truth” is the live manager state; “config truth” is unit files + drop-ins on disk.
- After editing unit files, you usually run
systemctl daemon-reloadto re-read configs. - Actions can apply system-wide (root) or per-user with
systemctl --user.
Quick Start
# Minimal “prove it works” example systemctl --version # Show if the machine is considered "healthy" by systemd systemctl is-system-running
10 Practical Examples
# 1) Check the status of a service (replace sshd with your service name) systemctl status sshd
# 2) Start a service now (runtime action) sudo systemctl start sshd
# 3) Stop a service now (runtime action) sudo systemctl stop sshd
# 4) Restart a service (common after config changes) sudo systemctl restart sshd
# 5) Enable a service at boot (persistent) sudo systemctl enable sshd
# 6) Disable a service at boot (persistent) sudo systemctl disable sshd
# 7) See failed units (fast triage) systemctl --failed
# 8) List active services (running) systemctl list-units --type=service --state=running
# 9) Find where a unit file is coming from + show its contents systemctl cat sshd
# 10) After editing unit files / drop-ins, reload manager config, then restart sudo systemctl daemon-reload sudo systemctl restart sshd
Notes & Gotchas
- Enable vs start:
enableaffects boot-time;startaffects now. Often you want both. - daemon-reload: required after changing unit files or drop-ins (it does not restart services by itself).
- Masking:
systemctl maskprevents a unit from being started (stronger than disable). - Names: units often end in
.service,.socket,.timer,.target; you can usually omit the suffix. - Be careful on servers: stopping network/ssh services remotely can lock you out.
Historical Context
Before systemd, Linux often used SysV init scripts (e.g., /etc/init.d/) and tools like
service, chkconfig, or update-rc.d. systemd unified startup, service supervision,
dependency handling, and logging integration into one manager.
Modern Equivalent
On systemd systems, systemctl is the modern interface. For log viewing paired with it, use
journalctl. For deeper unit inspection, combine systemctl with systemd-analyze.
Related Commands
- journalctl — view logs for a unit (e.g.,
journalctl -u sshd). - systemd-analyze — boot timing + dependency insights.
- loginctl — inspect sessions/seats/users under systemd-logind.
- timedatectl — manage time/timezone via systemd-timesyncd and related components.
- hostnamectl — manage static/transient hostname.