systemctl Command in Linux: Start, Stop, Enable, and Manage Services
Learn systemctl command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
11 min read
Learn systemctl command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
- What systemctl Does and When to Use It
- Availability and Installation Across Linux Distributions
- Command Syntax, Arguments, and Exit Status Codes
Interactive Builder for this Guide
Build your custom systemd syntax (systemctl Command in Linux: Start, Stop, Enable, and Manage Services)
[Unit] Description=Core API Node Service After=network-online.target Wants=network-online.target [Service] Type=simple User=www-data WorkingDirectory=/opt/myapp EnvironmentFile=/opt/myapp/.env ExecStart=/usr/bin/node dist/server.js Restart=on-failure RestartSec=5 NoNewPrivileges=true [Install] WantedBy=multi-user.target
After=network-online.targetWaits until host networking is online before launchingUser=www-dataRuns process with least privilege instead of rootRestart=on-failureAutomatically recovers process after crashes (delay 5s)NoNewPrivileges=trueSecurity hardening preventing child privilege escalationMastering the systemctl command in linux is fundamental to administering almost every modern Linux distribution, including Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, SUSE, and Arch Linux. As the command-line frontend to systemd (PID 1), systemctl replaces legacy System V tools such as service, chkconfig, update-rc.d, and telinit with a unified interface.
The systemctl command in Linux is the primary control utility for the systemd init system and service manager. Use sudo systemctl start, stop, restart, or reload <service> to control running daemons immediately, sudo systemctl enable or disable <service> to configure automatic startup at boot, and systemctl status <service> to inspect real-time process health, cgroup membership, and recent journal logs.
Beyond starting and stopping background daemons (.service units), systemctl orchestrates socket activation (.socket), scheduled cron-like timers (.timer), filesystem mounts (.mount), device nodes (.device), resource control slices (.slice), and boot targets (.target). If you omit the unit suffix when running a command—such as typing systemctl status nginx—systemctl automatically appends .service.
A common point of confusion for new administrators is the separation between runtime state and boot-time persistence: systemctl start launches a service right now without enabling it for future reboots, whereas systemctl enable creates the boot symlinks without starting the service immediately—unless you combine both actions using the convenient --now flag.
What systemctl Does and When to Use It
When you invoke systemctl, it communicates with the systemd manager process (PID 1 for system units, or the per-user systemd --user instance when --user is passed) over D-Bus or the private UNIX domain socket /run/systemd/private. Systemd tracks every service inside a dedicated Linux Control Group (cgroup v2) hierarchy under /sys/fs/cgroup/system.slice/, ensuring that even if a daemon double-forks child processes, systemd can accurately monitor, resource-limit, and terminate every process belonging to that unit.
Unit configuration files are loaded according to a strict three-tier precedence order: vendor package defaults live in /lib/systemd/system/ (or /usr/lib/systemd/system/), transient runtime units live in /run/systemd/system/, and local administrator overrides and custom units live in /etc/systemd/system/. Whenever you edit a unit file or add a drop-in override in /etc/systemd/system/<unit>.d/override.conf, you must run sudo systemctl daemon-reload so PID 1 re-parses the dependency graph in memory.
Under the hood, systemctl gathers runtime telemetry or dispatches control signals by reading virtual filesystems mounted at /proc and /sys, or by communicating with PID 1 (systemd) over D-Bus. Using flags such as --now, --user, -H, -l turns raw process and service tables into actionable diagnostics during incident response.
Availability and Installation Across Linux Distributions
The systemctl utility is packaged in systemd across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:
Before running administrative tasks or automation scripts, verify whether systemctl is installed and inspect which binary path and version your shell resolves:
type -a systemctl
systemctl --version 2>/dev/null || man -f systemctl
# Illustrative output (reviewed against documentation)
systemctl is /usr/bin/systemctl
systemctl (systemd)
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y systemd
# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y systemd
# Arch Linux
sudo pacman -S --noconfirm systemd
# Alpine Linux
sudo apk add --no-cache openrc
Command Syntax, Arguments, and Exit Status Codes
systemctl [OPTIONS] COMMAND [UNIT...]
The command structure follows systemctl [OPTIONS] SUBCOMMAND [UNIT...]. Subcommands fall into four primary categories: runtime lifecycle verbs (start, stop, restart, reload, try-restart, reload-or-restart, kill), boot enablement verbs (enable, disable, reenable, mask, unmask), inspection verbs (status, is-active, is-enabled, is-failed, show, cat), and system state verbs (daemon-reload, isolate, reboot, poweroff).
Multiple unit names or shell-quoted glob patterns can be passed in a single invocation, such as systemctl status 'nginx*' 'php*-fpm.service'. State-mutating operations on the system manager require root privileges via sudo or interactive Polkit authentication, while read-only queries like status, is-active, and cat can be run by any regular user.
0— Successful execution with no runtime or permission errors.1— Operational failure, unmatched condition, or permission restriction.2— Invalid command-line option or malformed syntax.
Important Options and Flags Reference
| Option / Flag | Long Form / Argument | Technical Behavior and Purpose |
|---|---|---|
--now | --now | When combined with enable, disable, or mask, also immediately starts or stops the unit in the same command. |
--user | --user | Talks to the calling user's personal systemd manager instance rather than the system-wide PID 1 daemon. |
-H | --host=[USER@]HOST | Executes the systemctl operation remotely on the specified host over an SSH transport connection. |
-l | --full | Prevents systemctl status from ellipsizing (truncating) long log lines and process command-line arguments. |
-n | --lines=INTEGER | Controls how many recent journal log lines are displayed at the bottom of systemctl status (default is 10). |
--no-pager | --no-pager | Prints output directly to standard output without piping through less, ideal for scripts and CI logs. |
-p | --property=NAME | Filters the output of systemctl show to display only specific unit properties (e.g., MainPID, ActiveState, ExecStart). |
-s | --signal=SIGNAL | Specifies which POSIX signal (e.g., SIGHUP, SIGTERM, SIGKILL) systemctl kill should send to the unit's processes. |
Two flag combinations dramatically improve daily workflow speed: sudo systemctl enable --now <service> (which enables boot startup and starts the daemon in one step) and systemctl status -l --no-pager -n 30 <service> (which prints 30 untruncated journal lines directly to the terminal).
When writing automated deployment or health-check scripts, avoid scraping human-oriented systemctl status text. Instead, use systemctl is-active --quiet <service> for boolean exit-code checks, or systemctl show --property=MainPID --value <service> to extract clean machine-readable values.
When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.
Practical Basic and Advanced Usage Examples
1. Inspect Detailed Service Health and Recent Logs with status
Check whether a service is active, enabled at boot, what its Main PID and memory footprint are, and view its most recent journal entries.
systemctl status nginx.service --no-pager
# Illustrative output (reviewed against documentation)
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Thu 2026-10-22 08:15:10 UTC; 11h ago
Docs: man:nginx(8)
Main PID: 1104 (nginx)
Tasks: 3 (limit: 9420)
Memory: 14.8M (peak: 18.2M)
CPU: 1.412s
CGroup: /system.slice/nginx.service
├─ 1104 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
├─29410 "nginx: worker process"
└─29411 "nginx: worker process"
The Loaded line shows the unit file path and boot state (enabled), Active shows current runtime status and uptime, and CGroup renders the full process tree inside the service's slice.
2. Start, Stop, and Restart a Service
Use start, stop, or restart to control the immediate runtime execution of a systemd service unit.
sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl restart nginx
# Illustrative output (reviewed against documentation)
# Commands return no output on success (exit code 0).
By Unix convention, systemctl start, stop, and restart produce zero output when they succeed; if a startup hook fails, systemctl prints an error directing you to systemctl status and journalctl -xeu.
3. Reload Configuration Gracefully Without Dropping Connections
Use reload or reload-or-restart when you modify configuration files (such as nginx.conf or sshd_config) and want to apply changes without interrupting active connections.
sudo nginx -t
sudo systemctl reload-or-restart nginx
# Illustrative output (reviewed against documentation)
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
reload runs the unit's ExecReload directive (typically sending SIGHUP). Using reload-or-restart reloads the daemon if it supports hot reloads and falls back to a full restart if it does not or is currently stopped.
4. Enable and Start a Service in One Command with --now
Configure a newly installed daemon to start automatically on every future system boot and launch it immediately using --now.
sudo systemctl enable --now redis-server.service
systemctl is-enabled redis-server.service
systemctl is-active redis-server.service
# Illustrative output (reviewed against documentation)
Synchronizing state of redis-server.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable redis-server
Created symlink /etc/systemd/system/multi-user.target.wants/redis-server.service → /usr/lib/systemd/system/redis-server.service.
enabled
active
enable creates the target symbolic link specified in the unit's [Install] section, and --now triggers an immediate start.
5. Mask a Service to Completely Prevent Manual or Dependency Startup
While disable stops a service from starting automatically at boot, another unit or manual command can still start it. Use mask to symlink the unit to /dev/null so it cannot be started under any circumstance.
sudo systemctl mask --now bluetooth.service
sudo systemctl start bluetooth.service || true
# Restore normal behavior later with unmask:
sudo systemctl unmask bluetooth.service
# Illustrative output (reviewed against documentation)
Created symlink /etc/systemd/system/bluetooth.service → /dev/null.
Failed to start bluetooth.service: Unit bluetooth.service is masked.
Removed "/etc/systemd/system/bluetooth.service".
Masking is a popular hardening technique for ensuring unused services (like cups, avahi-daemon, or bluetooth) can never be socket-activated or pulled in by package updates.
6. Inspect Unit File Contents and Create a Safe Drop-In Override
View the effective unit file configuration with systemctl cat and Query machine-readable properties with systemctl show.
systemctl cat ssh.service | head -n 15
systemctl show ssh.service --property=MainPID,ActiveState,Restart,MemoryCurrent
# Illustrative output (reviewed against documentation)
# /usr/lib/systemd/system/ssh.service
[Unit]
Description=OpenBSD Secure Shell server
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
MainPID=892
ActiveState=active
Restart=on-failure
MemoryCurrent=7864320
systemctl cat displays the base vendor unit file plus any drop-in overrides applied from /etc/systemd/system/<unit>.d/*.conf in exact load order.
Real-World Workflows, Pipelines, and Shell Automation
Automated Service Health Check and Self-Healing Recovery Loop
Check critical application services using systemctl is-active --quiet, capture diagnostic logs on failure, attempt a restart, and verify recovery.
#!/usr/bin/env bash
set -euo pipefail
SERVICES=("nginx.service" "postgresql.service" "redis-server.service")
for svc in "${SERVICES[@]}"; do
if systemctl is-active --quiet "$svc"; then
PID=$(systemctl show -p MainPID --value "$svc")
echo "[OK] $svc is active (MainPID: $PID)"
else
echo "[WARN] $svc is not active! Capturing last 10 journal lines and restarting..." >&2
sudo journalctl -u "$svc" -n 10 --no-pager >&2
sudo systemctl restart "$svc"
if systemctl is-active --quiet "$svc"; then
echo "[RECOVERED] $svc successfully restarted."
else
echo "[CRITICAL] $svc failed to restart!" >&2
exit 1
fi
fi
done
# Illustrative output (reviewed against documentation)
[OK] nginx.service is active (MainPID: 1104)
[OK] postgresql.service is active (MainPID: 984)
[OK] redis-server.service is active (MainPID: 1250)
Using systemctl is-active --quiet avoids text parsing and returns exit code 0 only when the unit is actively running.
Apply Resource Limits via Non-Destructive Drop-In Overrides
Instead of editing vendor files in /usr/lib/systemd/system/ (which get overwritten by apt or dnf updates), create a drop-in override file, reload the daemon, and restart the service.
sudo mkdir -p /etc/systemd/system/nginx.service.d
cat << 'EOF' | sudo tee /etc/systemd/system/nginx.service.d/limits.conf
[Service]
LimitNOFILE=65535
MemoryMax=512M
Restart=on-failure
RestartSec=3s
EOF
sudo systemctl daemon-reload
sudo systemctl restart nginx.service
systemctl show nginx.service -p LimitNOFILE,MemoryMax,Restart
# Illustrative output (reviewed against documentation)
[Service]
LimitNOFILE=65535
MemoryMax=512M
Restart=on-failure
RestartSec=3s
LimitNOFILE=65535
MemoryMax=536870912
Restart=on-failure
Drop-in files inside /etc/systemd/system/<service>.d/*.conf merge cleanly on top of vendor package units and survive future OS package upgrades.
Pipelines, Redirection, Quoting, and Shell Expansion
When embedding systemctl inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.
Permissions, Security Implications, and Safe Execution
Never stop or mask critical connectivity or boot services (such as ssh.service, systemd-networkd.service, NetworkManager.service, or dbus.service) over a remote SSH session, or you will immediately lock yourself out of the server.
Allowing a non-root user to run sudo systemctl without arguments or with wildcard editing subcommands (systemctl edit) is equivalent to granting full root access, because unit files execute arbitrary commands as root by default and interactive pagers (less) allow shell escapes via !sh unless SYSTEMD_LESS=FRXMK (secure mode) is enforced.
When granting restricted sudo rights to application deployers in /etc/sudoers.d/, always specify the exact binary path and exact subcommand/unit arguments, such as %deployers ALL=(root) NOPASSWD: /usr/bin/systemctl restart myapp.service, /usr/bin/systemctl status --no-pager myapp.service.
GNU/Linux, BSD, and BusyBox Implementation Differences
systemctl is exclusive to Linux distributions that boot with systemd as PID 1 (Debian, Ubuntu, RHEL, Rocky, AlmaLinux, Fedora, SUSE, Arch).
On Alpine Linux (OpenRC), use rc-service <name> start|stop|status and rc-update add <name> default. Inside minimal Docker or Kubernetes containers where PID 1 is the application binary itself rather than systemd, running systemctl fails with System has not been booted with systemd as init system (PID 1). Can't operate.
Troubleshooting Common Errors and Diagnostics
Warning: The unit file, source configuration file or drop-ins of <unit> changed on disk
Root Cause: A unit file in /etc/systemd/system or /usr/lib/systemd/system was modified on disk, but PID 1 is still using the cached configuration in memory.
Resolution: Run sudo systemctl daemon-reload to refresh systemd's in-memory configuration before restarting the unit.
sudo systemctl daemon-reload
sudo systemctl restart myapp.service
Failed to start <unit>.service: Start request repeated too quickly
Root Cause: The service crashed repeatedly within StartLimitIntervalSec (default 10s) more than StartLimitBurst times (default 5), triggering systemd's crash-loop protection.
Resolution: Fix the underlying application error found in journalctl -u <unit>, reset the failed counter with systemctl reset-failed, and start the service again.
sudo journalctl -u myapp.service -n 25 --no-pager
sudo systemctl reset-failed myapp.service
sudo systemctl start myapp.service
System has not been booted with systemd as init system (PID 1). Can't operate.
Root Cause: You are running inside a Docker container, chroot environment, or WSL instance where PID 1 is not systemd.
Resolution: Start the daemon executable directly in the container entrypoint or run the service script if available.
ps -p 1 -o pid,comm,args
Alternatives, Related Commands, and Related Tutorials
- How to Create a systemd Service in Linux: Unit File Tutorial — Practical syntax, flags, and examples for
systemd. - List Linux Services with systemctl: Status, Units, and States — Practical syntax, flags, and examples for
systemctl. - reboot Command in Linux: Restart with systemctl and shutdown — Practical syntax, flags, and examples for
reboot. - How to Kill a Process in Linux: kill, killall, and pkill Guide — Practical syntax, flags, and examples for
kill. - 25 Best Linux Commands Every Sysadmin Should Know — Core command-line utilities for daily Linux server administration.
- How to Find a File in Linux from the Command Line — Practical file search patterns across Linux directories.
- Linux Commands Knowledge Hub (#linux-commands) — Browse all Linux command-line tutorials and system administration references.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
/dev/null, making it impossible to start manually or automatically until unmasked./etc/systemd/system/ or modify a drop-in override file so systemd reloads the unit definitions from disk.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides

Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!