⚙️ systemctl Quick Reference

Service and unit management — the commands you use every day

systemctl is the primary command for interacting with systemd — the init system and service manager on all modern Linux distributions. It controls services, targets, timers, mounts, sockets, and more. If you need to start it, stop it, check it, or schedule it — systemctl is how you do it.

📚 This page is a quick-reference companion. For deep-dive coverage see: systemctl Complete Reference  |  Creating systemd Service Units

Unit Types

.service

Daemons and programs — the most common type

.timer

Scheduled tasks — modern cron replacement

.target

Grouping units — analogous to runlevels

.socket

Socket-activated services

.mount

Filesystem mount points

.path

Path-based activation

.slice

Resource control groups

.scope

Externally created processes

Syntax note: When working with .service units you can omit the extension — systemctl status sshd and systemctl status sshd.service are equivalent.

Service Management

Start · Stop · Restart · Reload

CommandWhat it does
systemctl start sshdStart the service now (does not affect boot)
systemctl stop sshdStop the service now
systemctl restart sshdStop then start — drops all connections
systemctl reload sshdReload config without stopping (if supported)
systemctl reload-or-restart sshdReload if supported, restart otherwise
systemctl try-restart sshdRestart only if currently running
systemctl kill sshdSend signal to all processes of the unit

Enable · Disable (Boot Persistence)

CommandWhat it does
systemctl enable sshdEnable at boot (creates symlink)
systemctl disable sshdDisable at boot (removes symlink)
systemctl enable --now sshdEnable AND start immediately
systemctl disable --now sshdDisable AND stop immediately
systemctl reenable sshdDisable then re-enable (reset symlinks)
systemctl mask sshdPrevent start completely — even manually
systemctl unmask sshdRemove mask
💡 enable --now is the pattern you want for most provisioning work — one command starts the service and ensures it survives reboots.
⚠️ mask vs disable: disable stops autostart but still allows manual start. mask symlinks the unit to /dev/null — nothing can start it until unmasked. Use mask for services you want completely locked out (e.g., telnet.socket).

Status and Inspection

Checking Status

CommandWhat it does
systemctl status sshdFull status — state, PID, recent journal lines
systemctl is-active sshdPrints "active" or "inactive" — good for scripts
systemctl is-enabled sshdPrints "enabled", "disabled", "masked"
systemctl is-failed sshdReturns 0 if unit is in failed state
systemctl show sshdAll properties of the unit (machine-readable)
systemctl show -p MainPID sshdShow a single property
systemctl cat sshdDisplay the unit file as loaded

Listing Units

CommandWhat it does
systemctl list-unitsAll active units
systemctl list-units --allAll units including inactive
systemctl list-units --type=serviceServices only
systemctl list-units --state=failedFailed units only — first stop after boot
systemctl list-unit-filesAll installed unit files and their state
systemctl list-unit-files --type=serviceService unit files only
systemctl list-timersAll timers with next/last trigger times
systemctl list-socketsAll socket units
systemctl list-dependencies sshdDependency tree for a unit
# Practical — see what failed on boot
systemctl list-units --state=failed

# Find all enabled services
systemctl list-unit-files --type=service --state=enabled

# Script-friendly status check
systemctl is-active nginx && echo "running" || echo "not running"

Configuration

After Editing Unit Files

CommandWhat it does
systemctl daemon-reloadRe-read all unit files — required after any edit
systemctl edit sshdOpen a drop-in override (preferred over editing originals)
systemctl edit --full sshdEdit a full copy of the unit file
systemctl revert sshdRemove overrides, restore original unit
Unit file locations:
/lib/systemd/system/ — distro-provided (do not edit)
/etc/systemd/system/ — your overrides and custom units (edit here)
/etc/systemd/system/sshd.service.d/ — drop-in override directory
💡 Always daemon-reload after creating or editing any unit file. systemd reads unit files at load time — without a reload it will keep using the old version.

Targets (Runlevels)

Common Targets

TargetSysV EquivalentDescription
poweroff.targetrunlevel 0Shut down and power off
rescue.targetrunlevel 1Single-user rescue mode
multi-user.targetrunlevel 3Multi-user, no GUI — typical server default
graphical.targetrunlevel 5Multi-user with GUI
reboot.targetrunlevel 6Reboot
emergency.targetMinimal emergency shell

Target Commands

CommandWhat it does
systemctl get-defaultShow current default boot target
systemctl set-default multi-user.targetSet default boot target
systemctl isolate rescue.targetSwitch to target now (stops other units)

Power Management

CommandWhat it does
systemctl poweroffShut down and power off
systemctl rebootReboot
systemctl haltHalt (may not power off)
systemctl suspendSuspend to RAM
systemctl hibernateSuspend to disk
systemctl rescueDrop to single-user rescue mode
systemctl emergencyDrop to emergency shell (minimal)

Essential Companion — journalctl

systemctl status shows a few log lines. For the full picture use journalctl:

# All logs for a unit
journalctl -u sshd

# Follow logs live (like tail -f)
journalctl -u sshd -f

# Logs since last boot
journalctl -u sshd -b

# Last 50 lines
journalctl -u sshd -n 50

# Kernel messages only
journalctl -k

# All errors and above, this boot
journalctl -b -p err

Common Workflows

Deploy a New Service

# 1. Place unit file
sudo cp myapp.service /etc/systemd/system/

# 2. Reload systemd
sudo systemctl daemon-reload

# 3. Enable and start
sudo systemctl enable --now myapp

# 4. Verify
systemctl status myapp

Diagnose a Failed Service

# See what failed
systemctl list-units --state=failed

# Get details
systemctl status myapp

# Read the full log
journalctl -u myapp -b --no-pager

# After fixing — reset failed state and restart
sudo systemctl reset-failed myapp
sudo systemctl start myapp

Override a Vendor Unit File

# Opens editor for a drop-in override — safe, non-destructive
sudo systemctl edit sshd

# Example override content to increase connection limit:
# [Service]
# LimitNOFILE=65536

# Reload after saving
sudo systemctl daemon-reload
sudo systemctl restart sshd
💡 Never edit files in /lib/systemd/system/ directly — package updates will overwrite your changes. Always use systemctl edit to create a drop-in, or copy to /etc/systemd/system/ and edit there.

Boot Analysis

CommandWhat it does
systemd-analyzeTotal boot time summary
systemd-analyze blamePer-unit boot time, sorted slowest first
systemd-analyze critical-chainCritical path through boot sequence
systemd-analyze plot > boot.svgGenerate SVG boot timeline chart
systemd-analyze verify myapp.serviceValidate a unit file for errors