Linux

Managing Linux Services with systemctl: A Complete Guide

In this guide, you'll master essential and advanced systemctl commands for full service management in Linux. Learn to start, stop, configure autostart, and diagnose service issues.

Updated at February 15, 2026
15-20 min
Easy
FixPedia Team
Применимо к:Ubuntu 20.04+CentOS/RHEL 8+Debian 11+Fedora 35+Any distribution with systemd

Introduction / Why This Is Needed

systemctl is the primary utility for managing systemd, the init system and service manager used in the vast majority of modern Linux distributions (Ubuntu, CentOS, Debian, Fedora, etc.). With it, you can control the lifecycle of background processes (services), such as web servers, databases, network daemons, and many other system components.

By the end of this guide, you will confidently manage services: start, stop, configure their autostart, reload configurations, and diagnose issues. These skills are an essential foundation for any system administrator and developer working with servers.

Prerequisites / Preparation

  1. Access to a Linux terminal with systemd installed. You can verify its presence with:
    ps -p 1 -o comm=
    
    The command should return systemd.
  2. Superuser privileges (root or sudo) to manage most system services. For managing user services, root privileges may not be required.
  3. Basic understanding of the command line and service naming conventions (they usually have a .service extension, e.g., nginx.service or sshd.service).

Step 1: Checking Service Status

Before taking any action, it's useful to know the current state of a service.

sudo systemctl status <service_name>.service
  • Example: sudo systemctl status nginx.service
  • What it does: Displays detailed information: whether the unit is active, if it started successfully, the process PID, last start time, and the latest log entries for that service.
  • Short forms: For a simple status output (active/inactive), use systemctl is-active <service_name> or systemctl is-enabled <service_name> (shows if autostart is enabled).

Step 2: Basic Management (Start, Stop)

These commands manage the service in the current session, without persisting the state after a reboot.

# Start the service immediately
sudo systemctl start <service_name>.service

# Stop the service
sudo systemctl stop <service_name>.service
  • Example: sudo systemctl start apache2.service
  • Important: If the service is already running, the start command does nothing. If it's stopped, stop also has no effect. For a forceful restart, see the next step.

Step 3: Configuring Autostart (enable/disable)

To have a service start automatically on every system boot, you must "enable" it.

# Enable the service to start at boot
sudo systemctl enable <service_name>.service

# Disable the service from starting at boot
sudo systemctl disable <service_name>.service
  • What happens: enable creates symbolic links in the /etc/systemd/system/ (or /lib/systemd/system/) directory, instructing systemd to start this service when reaching a specific target level, typically multi-user.target or graphical.target.
  • Useful command: systemctl is-enabled <service_name>.service will show if autostart is configured (enabled/disabled/static/masked).

Step 4: Restarting and Reloading Configuration

Often, after modifying a service's configuration file (e.g., /etc/nginx/nginx.conf), you need to apply changes without a full stop.

# Full restart (stop and start again)
sudo systemctl restart <service_name>.service

# Reload configuration (without stopping, if the service supports it)
sudo systemctl reload <service_name>.service
  • Critical difference: restart guarantees the service starts fresh with a clean environment but causes a brief downtime. reload is a more "graceful" operation, but not all services support it. If reload is unavailable, systemd will report it.
  • Alternative: sudo systemctl try-reload-or-restart <service_name>.service will attempt reload, and if that fails, it will perform restart.


Step 5: Viewing Service Logs

Diagnostics start with logs. journalctl is the tool for working with the systemd journal.

# Show all logs for a specific service
sudo journalctl -u <service_name>.service

# Show logs from the current system boot (after the last reboot)
sudo journalctl -u <service_name>.service -b

# Follow logs in real-time (like tail -f)
sudo journalctl -u <service_name>.service -f
  • Filters: Add --since "2024-01-01 10:00:00" to filter by time or -p err to show only error messages.
  • Helpful: The combination of systemctl status and journalctl allows you to quickly understand why a service fails to start or behaves unstably.

Step 6: Additional Useful Operations

Isolating a Target (System Reboot to a Runlevel)

Switching systemd to a different target level, similar to changing runlevels in SysVinit.

# Switch to multi-user mode without a graphical interface (like runlevel 3)
sudo systemctl isolate multi-user.target

# Switch back to graphical mode (like runlevel 5)
sudo systemctl isolate graphical.target

Masking/Unmasking a Service

An extreme measure that prevents any start of the service, even manually or as a dependency.

# Completely block the service (creates a symlink to /dev/null)
sudo systemctl mask <service_name>.service

# Unblock the service
sudo systemctl unmask <service_name>.service
  • Caution: Use mask carefully. You can mask a critical service (like sshd), after which console access may be required to unmask it.

Reloading the Daemon (Daemon-Reload)

After modifying a unit file (the .service file itself, e.g., in /etc/systemd/system/), you need to inform systemd of the changes.

sudo systemctl daemon-reload
  • When: Always after manually editing or creating a new service file, but before restarting it (restart).

Verifying the Result

  1. Check the status: sudo systemctl status <service_name>.service. Ensure the Active: line shows active (running) for running services or inactive (dead) for stopped ones.
  2. Check autostart: systemctl is-enabled <service_name>.service should return enabled.
  3. Test functionality: For a web server, make an HTTP request (curl http://localhost); for SSH, try to connect. This is the most reliable way to confirm the service is working correctly, not just "started".

Common Issues

Problem / SymptomLikely CauseSolution
Failed to start <service>.serviceError in the service's configuration file or dependencies.1. Run sudo systemctl status <service>.service and look for the Result: line.
2. Check logs: sudo journalctl -u <service>.service -b -p err.
3. Validate configuration syntax (if a -t flag exists, e.g., nginx -t).
Unit <service>.service not found.Service not installed, name misspelled, or unit file missing.1. Verify the name is correct.
2. Search for the file: sudo find / -name "*<part_of_name>*.service" 2>/dev/null.
3. If the service isn't installed—install the corresponding package (e.g., sudo apt install nginx).
Permission denied on start/stopRunning without superuser privileges (sudo).All system service management operations require sudo. Use sudo systemctl ... or log in as root.
Service starts but doesn't work (port not listening, process unresponsive)Problem within the service itself (code error, lack of resources, port conflict).1. Check if the process is running: ps aux | grep <process_name>.
2. Check if the port is listening: sudo ss -tulpn | grep :<port>.
3. Examine the application's own logs (not just journald) in /var/log/ or as specified in its config.
masked service won't start, even after enableThe service was blocked (mask).Unmask it: sudo systemctl unmask <service>.service, then sudo systemctl enable --now <service>.service.

F.A.Q.

How to check which services are currently active?
What's the difference between `systemctl restart` and `systemctl reload`?
How to make a service start automatically at boot?
What does the error 'Failed to start <service>.service' mean?

Hints

Checking the status of an existing service
Basic management: start and stop
Configuring autostart
Restarting and reloading configuration
Viewing service logs
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community