Complete Guide to Linux systemd Service Management for Absolute Beginners

Master systemd service management with systemctl commands. Learn how to start, stop, restart, enable, disable services, view service status, analyze unit files, check dependencies, and monitor logs with journalctl on RHEL/CentOS/Fedora systems.

28 min read

Introduction

systemd is the modern init system and service manager for Linux, replacing older SysV init and Upstart systems. It's responsible for starting services during boot, managing running services, and handling system state transitions. Understanding systemd is essential for managing Linux servers and workstations.

In this comprehensive guide, you'll learn:

  • Listing and filtering systemd services
  • Checking service status with detailed output interpretation
  • Starting, stopping, and restarting services
  • Enabling and disabling services for automatic startup
  • Viewing and understanding systemd unit files
  • Analyzing service dependencies
  • Monitoring service logs with journalctl
💡

What is systemd? systemd is a system and service manager that initializes and manages all processes on a Linux system. It uses "units" (service files) to define how services should be started, stopped, and managed.

Understanding systemd Units

systemd manages different types of units:

Unit TypeExtensionPurposeExample
Service.serviceSystem services and daemonssshd.service, nginx.service
Socket.socketIPC or network socketdocker.socket
Target.targetGroup of units (like runlevels)multi-user.target
Mount.mountFilesystem mount pointhome.mount
Timer.timerScheduled tasks (like cron)backup.timer

Listing Running Services

To view all currently running services:

systemctl list-units --type=service --state=running

Command Breakdown:

  • systemctl: Main command for controlling systemd
  • list-units: List all loaded units
  • --type=service: Filter to show only service units
  • --state=running: Show only running services

Partial Output:

  UNIT                          LOAD   ACTIVE SUB     DESCRIPTION
  accounts-daemon.service       loaded active running Accounts Service
  alsa-state.service            loaded active running Manage Sound Card State (restore and store)
  atd.service                   loaded active running Deferred execution scheduler
  auditd.service                loaded active running Security Auditing Service
  avahi-daemon.service          loaded active running Avahi mDNS/DNS-SD Stack
  chronyd.service               loaded active running NTP client/server
  colord.service                loaded active running Manage, Install and Generate Color Profiles
  containerd.service            loaded active running containerd container runtime
  crond.service                 loaded active running Command Scheduler
  cups.service                  loaded active running CUPS Scheduler
  dbus-broker.service           loaded active running D-Bus System Message Bus
  docker.service                loaded active running Docker Application Container Engine
  firewalld.service             loaded active running firewalld - dynamic firewall daemon
  gdm.service                   loaded active running GNOME Display Manager
  NetworkManager.service        loaded active running Network Manager
  sshd.service                  loaded active running OpenSSH server daemon
  systemd-journald.service      loaded active running Journal Service
  systemd-logind.service        loaded active running User Login Management
  systemd-udevd.service         loaded active running Rule-based Manager for Device Events and Files

Understanding Column Headers

ColumnMeaningPossible Values
UNITService unit nameservicename.service
LOADUnit definition loaded statusloaded, not-found, masked
ACTIVEHigh-level activation stateactive, inactive, failed, activating
SUBLow-level unit staterunning, exited, failed, dead
DESCRIPTIONHuman-readable service descriptionText description

Footer Summary:

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
36 loaded units listed.

This shows 36 service units are currently running on the system.

Common Service Types:

  • System Services: auditd (security), chronyd (time sync), crond (scheduling)
  • Network Services: sshd (SSH server), NetworkManager (networking)
  • Desktop Services: gdm (display manager), accounts-daemon (user accounts)
  • Container Services: docker, containerd
  • Core systemd Services: systemd-journald (logging), systemd-logind (login)

Checking Service Status

The systemctl status command provides detailed information about a service:

systemctl status sshd

Output:

● sshd.service - OpenSSH server daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
     Active: active (running) since Mon 2025-10-06 15:43:12 PKT; 3h 18min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
   Main PID: 1861 (sshd)
      Tasks: 1 (limit: 48732)
     Memory: 2.0M (peak: 2.3M)
        CPU: 31ms
     CGroup: /system.slice/sshd.service
             └─1861 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Oct 06 15:43:12 localhost.localdomain systemd[1]: Starting OpenSSH server daemon...
Oct 06 15:43:12 localhost.localdomain sshd[1861]: Server listening on 0.0.0.0 port 22.
Oct 06 15:43:12 localhost.localdomain sshd[1861]: Server listening on :: port 22.
Oct 06 15:43:12 localhost.localdomain systemd[1]: Started OpenSSH server daemon.

Detailed Status Output Explanation

Line 1: Service Header

● sshd.service - OpenSSH server daemon
  • : Green dot indicates active/running (○ would mean inactive)
  • sshd.service: Full service unit name
  • OpenSSH server daemon: Service description

Line 2: Load Status

Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
FieldValueMeaning
LoadedloadedUnit file successfully loaded
Unit file path/usr/lib/systemd/system/sshd.serviceLocation of service definition file
enabledenabledWill start automatically at boot
presetenabledSystem default is to enable this service

Line 3: Active Status

Active: active (running) since Mon 2025-10-06 15:43:12 PKT; 3h 18min ago
ComponentValueMeaning
Active stateactive (running)Service is currently running
Start timeMon 2025-10-06 15:43:12 PKTWhen service was started
Uptime3h 18min agoHow long service has been running

Documentation Links:

Docs: man:sshd(8)
      man:sshd_config(5)
  • Provides manual page references for the service
  • man sshd for daemon documentation
  • man sshd_config for configuration file documentation

Process Information:

Main PID: 1861 (sshd)
Tasks: 1 (limit: 48732)
Memory: 2.0M (peak: 2.3M)
CPU: 31ms
MetricValueExplanation
Main PID1861 (sshd)Primary process ID and name
Tasks1 (limit: 48732)1 task/thread running, system limit 48,732
Memory2.0M (peak: 2.3M)Current 2MB, peak was 2.3MB
CPU31msTotal CPU time consumed (31 milliseconds)

CGroup (Control Group):

CGroup: /system.slice/sshd.service
        └─1861 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
  • CGroup path: /system.slice/sshd.service - hierarchical resource control
  • Process tree: Shows PID 1861 with full command line
  • -D: Run in foreground (don't daemonize)
  • [listener]: Current state (listening for connections)

Recent Logs (Last Few Lines):

Oct 06 15:43:12 localhost.localdomain systemd[1]: Starting OpenSSH server daemon...
Oct 06 15:43:12 localhost.localdomain sshd[1861]: Server listening on 0.0.0.0 port 22.
Oct 06 15:43:12 localhost.localdomain sshd[1861]: Server listening on :: port 22.
Oct 06 15:43:12 localhost.localdomain systemd[1]: Started OpenSSH server daemon.

Log Interpretation:

  1. systemd initiating service start
  2. sshd binding to IPv4 (0.0.0.0) port 22
  3. sshd binding to IPv6 (::) port 22
  4. systemd confirming successful start
💡

Installation Note: If sshd is not installed:

  • RHEL/Fedora/CentOS: sudo dnf install openssh-server
  • Ubuntu/Debian: sudo apt install openssh-server

Stopping Services

The systemctl stop command stops a running service:

sudo systemctl stop sshd

Why sudo is Required:

  • Stopping system services requires root privileges
  • Regular users cannot control system-wide services
  • Protects critical services from accidental termination

Verifying the Stop:

systemctl status sshd

Output:

○ sshd.service - OpenSSH server daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
     Active: inactive (dead) since Mon 2025-10-06 19:03:51 PKT; 5s ago
   Duration: 3h 20min 39.015s
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 1861 ExecStart=/usr/sbin/sshd -D $OPTIONS (code=exited, status=0/SUCCESS)
   Main PID: 1861 (code=exited, status=0/SUCCESS)
        CPU: 35ms

Oct 06 15:43:12 localhost.localdomain systemd[1]: Starting OpenSSH server daemon...
Oct 06 15:43:12 localhost.localdomain sshd[1861]: Server listening on 0.0.0.0 port 22.
Oct 06 15:43:12 localhost.localdomain sshd[1861]: Server listening on :: port 22.
Oct 06 15:43:12 localhost.localdomain systemd[1]: Started OpenSSH server daemon.
Oct 06 19:03:51 vbox systemd[1]: Stopping OpenSSH server daemon...
Oct 06 19:03:51 vbox sshd[1861]: Received signal 15; terminating.
Oct 06 19:03:51 vbox systemd[1]: sshd.service: Deactivated successfully.
Oct 06 19:03:51 vbox systemd[1]: Stopped OpenSSH server daemon.

Understanding Stopped Service Status

Key Changes from Running State:

FieldValueMeaning
Indicator○ (white circle)Service is inactive (vs ● green for active)
Activeinactive (dead)Service stopped, process terminated
Duration3h 20min 39.015sHow long service was running before stop
Processcode=exited, status=0/SUCCESSClean exit with success status
Main PID1861 (code=exited, status=0/SUCCESS)Process 1861 exited cleanly

Stop Sequence in Logs:

  1. Stopping OpenSSH server daemon... - systemd initiates stop
  2. Received signal 15; terminating. - sshd receives SIGTERM (graceful shutdown)
  3. Deactivated successfully. - Service cleanly deactivated
  4. Stopped OpenSSH server daemon. - Stop complete
💡

Signal 15 (SIGTERM) allows the service to shut down gracefully - close connections, save state, clean up resources. systemd waits for this to complete before forcefully killing if needed.

Starting Services

The systemctl start command starts a stopped service:

sudo systemctl start sshd

Checking After Start:

systemctl status sshd

Output:

● sshd.service - OpenSSH server daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
     Active: active (running) since Mon 2025-10-06 19:04:06 PKT; 5s ago
       Docs: man:sshd(8)
             man:sshd_config(5)
   Main PID: 31364 (sshd)
      Tasks: 1 (limit: 48732)
     Memory: 1.5M (peak: 1.8M)
        CPU: 21ms
     CGroup: /system.slice/sshd.service
             └─31364 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Oct 06 19:04:05 vbox systemd[1]: Starting OpenSSH server daemon...
Oct 06 19:04:06 vbox sshd[31364]: Server listening on 0.0.0.0 port 22.
Oct 06 19:04:06 vbox sshd[31364]: Server listening on :: port 22.
Oct 06 19:04:06 vbox systemd[1]: Started OpenSSH server daemon.

What Changed:

  • New PID: 31364 (was 1861) - fresh process created
  • Active: Now active (running) with green ●
  • Fresh logs: Shows recent start sequence
  • Memory reset: 1.5M current (new process baseline)

Restarting Services

The systemctl restart command stops and then starts a service:

sudo systemctl restart sshd

When to Use Restart:

  • After modifying configuration files
  • To clear service state/memory
  • To apply updates without full reload
  • To resolve stuck processes

Restart vs Stop/Start:

  • Restart: Atomic operation, minimal downtime
  • Stop then Start: Separate operations, can verify stop before starting
⚠️

Caution: Restarting services like sshd will disconnect active SSH sessions. Use with care on remote servers, or use systemctl reload sshd instead if supported.

Enabling Services for Auto-Start

The systemctl enable command configures a service to start automatically at boot:

sudo systemctl enable sshd

What This Does:

  • Creates symbolic links in systemd directories
  • Registers service to start during boot sequence
  • Does NOT start the service immediately (use systemctl enable --now for both)

Verification:

systemctl status sshd

Relevant Line:

Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)

The enabled status confirms the service will start at boot.

How Enable Works: When you enable a service, systemd creates a symbolic link:

/etc/systemd/system/multi-user.target.wants/sshd.service → /usr/lib/systemd/system/sshd.service

This links the service to the multi-user.target (like runlevel 3 in SysV), ensuring it starts when the system reaches multi-user mode.

Disabling Services

The systemctl disable command prevents a service from starting automatically at boot:

sudo systemctl disable sshd

Output:

Removed "/etc/systemd/system/multi-user.target.wants/sshd.service".

What Happened:

  • Removed symbolic link from target directory
  • Service will NOT start automatically at boot
  • Service remains running if currently active (disable ≠ stop)

Verification:

systemctl status sshd

Output:

● sshd.service - OpenSSH server daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; disabled; preset: enabled)
     Active: active (running) since Mon 2025-10-06 19:04:18 PKT; 34s ago

Key Observations:

  • Loaded status: Now shows disabled (was enabled)
  • Active status: Still active (running) - disable doesn't stop service
  • Preset: enabled means system default wants it enabled (but manually disabled)
💡

Enable vs Start:

  • enable: Auto-start at boot (persistent)
  • start: Start immediately (temporary until reboot)
  • enable --now: Both enable and start
  • disable: Prevent auto-start (doesn't stop running service)

Viewing Service Unit Files

The systemctl cat command displays the service unit file:

systemctl cat sshd

Output:

# /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.target
Wants=sshd-keygen.target

[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

Understanding Unit File Sections

[Unit] Section - General Information

DirectiveValueMeaning
DescriptionOpenSSH server daemonHuman-readable description
Documentationman:sshd(8) man:sshd_config(5)Links to documentation
Afternetwork.target sshd-keygen.targetStart AFTER these units (ordering)
Wantssshd-keygen.targetWeak dependency (start it if available)

[Service] Section - Service Behavior

DirectiveValueMeaning
TypenotifyService notifies systemd when ready
EnvironmentFile-/etc/sysconfig/sshdLoad env variables (- means optional)
ExecStart/usr/sbin/sshd -D $OPTIONSCommand to start service
ExecReload/bin/kill -HUP $MAINPIDCommand to reload config (SIGHUP)
KillModeprocessOnly kill main process (not children)
Restarton-failureAuto-restart if it fails
RestartSec42sWait 42 seconds before restart

[Install] Section - Enable/Disable Behavior

DirectiveValueMeaning
WantedBymulti-user.targetEnable creates symlink in this target's wants directory

Service Type Values:

  • simple: Exec command is main process (default)
  • forking: Service spawns child process (traditional daemons)
  • oneshot: Process exits after start (initialization tasks)
  • notify: Service sends ready notification to systemd (like sshd)

Analyzing Service Dependencies

The systemctl list-dependencies command shows what a service depends on:

systemctl list-dependencies sshd

Output (Partial):

sshd.service
● ├─system.slice
● ├─sshd-keygen.target
○ │ ├─sshd-keygen@ecdsa.service
○ │ ├─sshd-keygen@ed25519.service
○ │ └─sshd-keygen@rsa.service
● └─sysinit.target
●   ├─dev-hugepages.mount
●   ├─dev-mqueue.mount
●   ├─dracut-shutdown.service
...
●   ├─systemd-journald.service
●   ├─systemd-modules-load.service
●   ├─systemd-udevd.service
●   ├─cryptsetup.target
●   ├─local-fs.target

Understanding Dependencies

Dependency Tree Structure:

  • = Active/loaded dependency
  • = Inactive dependency
  • Tree shows hierarchical relationships

Key Dependencies for sshd:

DependencyTypePurpose
system.sliceResource controlCGroup for resource management
sshd-keygen.targetSSH keysGenerate SSH host keys if missing
sshd-keygen@*.serviceKey generationGenerate ECDSA, ED25519, RSA keys
sysinit.targetSystem initializationBasic system setup must complete first
systemd-journald.serviceLoggingJournal logging service
local-fs.targetFilesystemLocal filesystems mounted

Dependency Types in systemd:

  • Requires: Strong dependency - failure stops this unit
  • Wants: Weak dependency - failure doesn't affect this unit
  • After: Ordering - start after these units
  • Before: Ordering - start before these units

Viewing Service Logs with journalctl

systemd uses journald for centralized logging. The journalctl command queries these logs.

Viewing All Logs for a Service

sudo journalctl -u sshd

Command Breakdown:

  • journalctl: Query systemd journal
  • -u sshd: Filter for unit sshd (service)

Output:

Oct 06 15:43:12 localhost.localdomain systemd[1]: Starting OpenSSH server daemon...
Oct 06 15:43:12 localhost.localdomain sshd[1861]: Server listening on 0.0.0.0 port 22.
Oct 06 15:43:12 localhost.localdomain sshd[1861]: Server listening on :: port 22.
Oct 06 15:43:12 localhost.localdomain systemd[1]: Started OpenSSH server daemon.
Oct 06 19:03:51 vbox systemd[1]: Stopping OpenSSH server daemon...
Oct 06 19:03:51 vbox sshd[1861]: Received signal 15; terminating.
Oct 06 19:03:51 vbox systemd[1]: sshd.service: Deactivated successfully.
Oct 06 19:03:51 vbox systemd[1]: Stopped OpenSSH server daemon.
Oct 06 19:04:05 vbox systemd[1]: Starting OpenSSH server daemon...
Oct 06 19:04:06 vbox sshd[31364]: Server listening on 0.0.0.0 port 22.
Oct 06 19:04:06 vbox sshd[31364]: Server listening on :: port 22.
Oct 06 19:04:06 vbox systemd[1]: Started OpenSSH server daemon.
Oct 06 19:04:18 vbox systemd[1]: Stopping OpenSSH server daemon...
Oct 06 19:04:18 vbox sshd[31364]: Received signal 15; terminating.
Oct 06 19:04:18 vbox systemd[1]: sshd.service: Deactivated successfully.
Oct 06 19:04:18 vbox systemd[1]: Stopped OpenSSH server daemon.
Oct 06 19:04:18 vbox systemd[1]: Starting OpenSSH server daemon...
Oct 06 19:04:18 vbox sshd[31380]: Server listening on 0.0.0.0 port 22.
Oct 06 19:04:18 vbox sshd[31380]: Server listening on :: port 22.
Oct 06 19:04:18 vbox systemd[1]: Started OpenSSH server daemon.

Log Format:

  • Timestamp: Oct 06 19:04:18
  • Hostname: vbox
  • Process: systemd[1] or sshd[31380]
  • Message: Actual log entry

Time-Based Filtering

sudo journalctl -u sshd --since "1 hour ago"

Output (Last Hour Only):

Oct 06 19:03:51 vbox systemd[1]: Stopping OpenSSH server daemon...
Oct 06 19:03:51 vbox sshd[1861]: Received signal 15; terminating.
Oct 06 19:03:51 vbox systemd[1]: sshd.service: Deactivated successfully.
Oct 06 19:03:51 vbox systemd[1]: Stopped OpenSSH server daemon.
Oct 06 19:04:05 vbox systemd[1]: Starting OpenSSH server daemon...
Oct 06 19:04:06 vbox sshd[31364]: Server listening on 0.0.0.0 port 22.
Oct 06 19:04:06 vbox sshd[31364]: Server listening on :: port 22.
Oct 06 19:04:06 vbox systemd[1]: Started OpenSSH server daemon.
Oct 06 19:04:18 vbox systemd[1]: Stopping OpenSSH server daemon...
Oct 06 19:04:18 vbox sshd[31364]: Received signal 15; terminating.
Oct 06 19:04:18 vbox systemd[1]: sshd.service: Deactivated successfully.
Oct 06 19:04:18 vbox systemd[1]: Stopped OpenSSH server daemon.
Oct 06 19:04:18 vbox systemd[1]: Starting OpenSSH server daemon...
Oct 06 19:04:18 vbox sshd[31380]: Server listening on 0.0.0.0 port 22.
Oct 06 19:04:18 vbox sshd[31380]: Server listening on :: port 22.
Oct 06 19:04:18 vbox systemd[1]: Started OpenSSH server daemon.

Time Filter Options:

  • --since "2024-10-06 18:00:00": Specific datetime
  • --since "1 hour ago": Relative time
  • --since "today": Today's logs
  • --since "yesterday": Yesterday's logs
  • --until "10 minutes ago": Up to a time
  • --since "30 min ago" --until "10 min ago": Time range

Following Logs in Real-Time

sudo journalctl -u sshd -f

Command Options:

  • -f: Follow mode (like tail -f)
  • Shows existing logs, then streams new entries

Output:

Oct 06 19:04:06 vbox sshd[31364]: Server listening on :: port 22.
Oct 06 19:04:06 vbox systemd[1]: Started OpenSSH server daemon.
Oct 06 19:04:18 vbox systemd[1]: Stopping OpenSSH server daemon...
Oct 06 19:04:18 vbox sshd[31364]: Received signal 15; terminating.
Oct 06 19:04:18 vbox systemd[1]: sshd.service: Deactivated successfully.
Oct 06 19:04:18 vbox systemd[1]: Stopped OpenSSH server daemon.
Oct 06 19:04:18 vbox systemd[1]: Starting OpenSSH server daemon...
Oct 06 19:04:18 vbox sshd[31380]: Server listening on 0.0.0.0 port 22.
Oct 06 19:04:18 vbox sshd[31380]: Server listening on :: port 22.
Oct 06 19:04:18 vbox systemd[1]: Started OpenSSH server daemon.
^C

Press Ctrl+C to stop following.

Use Cases for -f:

  • Real-time monitoring during troubleshooting
  • Watching service behavior during testing
  • Observing connection attempts to SSH
  • Monitoring service starts/stops

Best Practices for systemd Service Management

Service Control Best Practices

  1. Always Check Status Before Actions

    systemctl status service_name  # Before start/stop/restart
    
    • Verify current state
    • Check for errors
    • Note the PID for troubleshooting
  2. Use Reload Instead of Restart When Possible

    systemctl reload nginx  # Reload config without dropping connections
    
    • Some services support reload (SIGHUP)
    • Less disruptive than restart
    • Check if service supports reload first
  3. Combine Enable and Start

    sudo systemctl enable --now service_name  # Enable AND start
    
    • Saves a command
    • Ensures immediate operation and persistence
  4. Verify After Making Changes

    systemctl status service_name  # After any change
    journalctl -u service_name -n 20  # Check recent logs
    

Security and Stability Practices

  1. Don't Disable Critical Services

    • Never disable: systemd-journald, systemd-logind, dbus
    • Understand dependencies before disabling
    • Check with systemctl list-dependencies
  2. Test Configuration Changes

    sudo systemctl daemon-reload  # After editing unit files
    sudo systemctl restart service_name  # Apply changes
    systemctl status service_name  # Verify success
    
  3. Monitor Failed Services

    systemctl --failed  # List all failed units
    systemctl reset-failed  # Clear failed state after fixing
    
  4. Use Masking for Permanent Disable

    sudo systemctl mask service_name  # Prevent all starts
    sudo systemctl unmask service_name  # Remove mask
    
    • Masked services cannot be started (even manually)
    • Use for services that conflict with alternatives

Logging and Troubleshooting Practices

  1. Check Logs When Services Fail

    journalctl -u service_name -n 50  # Last 50 lines
    journalctl -u service_name --since "5 min ago"  # Recent
    journalctl -xe  # System-wide errors with explanation
    
  2. Set Log Retention

    # Edit /etc/systemd/journald.conf
    SystemMaxUse=500M  # Max disk space for logs
    MaxRetentionSec=1month  # Keep logs for 1 month
    
  3. Filter by Priority

    journalctl -p err  # Only errors
    journalctl -p warning -u service_name  # Warnings for specific service
    
    • Priorities: emerg, alert, crit, err, warning, notice, info, debug
  4. Export Logs for Analysis

    journalctl -u service_name --since today --no-pager > service.log
    

Operational Best Practices

  1. Document Custom Services

    • Maintain README for custom unit files
    • Document dependencies and configuration
    • Note restart/reload behavior
  2. Use Targets for Group Management

    systemctl isolate multi-user.target  # Text mode
    systemctl isolate graphical.target  # GUI mode
    
  3. Schedule Maintenance Windows

    • Restart services during low-traffic periods
    • Use timers for periodic tasks instead of cron
    • Test in staging before production
  4. Backup Configuration

    cp /etc/systemd/system/service_name.service /root/backup/
    
    • Backup before modifying unit files
    • Version control custom units

Command Cheat Sheet

Basic Service Control

CommandPurpose
systemctl start serviceStart a service immediately
systemctl stop serviceStop a running service
systemctl restart serviceStop and start service
systemctl reload serviceReload configuration (if supported)
systemctl status serviceShow service status and recent logs

Enable/Disable Services

CommandPurpose
systemctl enable serviceAuto-start at boot
systemctl disable servicePrevent auto-start at boot
systemctl enable --now serviceEnable and start immediately
systemctl mask serviceCompletely disable (prevent all starts)
systemctl unmask serviceRemove mask
systemctl is-enabled serviceCheck if enabled

Listing and Querying

CommandPurpose
systemctl list-units --type=serviceList all loaded services
systemctl list-units --type=service --state=runningList running services
systemctl list-units --type=service --state=failedList failed services
systemctl list-unit-filesList all unit files (installed services)
systemctl --failedShow failed units
systemctl cat serviceShow unit file content
systemctl list-dependencies serviceShow service dependencies

journalctl Log Commands

CommandPurpose
journalctl -u serviceShow all logs for service
journalctl -u service -fFollow logs in real-time
journalctl -u service -n 50Show last 50 log lines
journalctl -u service --since "1 hour ago"Logs from last hour
journalctl -u service --since todayToday's logs
journalctl -xeRecent errors with explanation
journalctl -p errOnly error level logs
journalctl --disk-usageShow journal disk usage
journalctl --vacuum-time=2weeksDelete logs older than 2 weeks

System State Commands

CommandPurpose
systemctl daemon-reloadReload systemd configuration (after editing unit files)
systemctl rebootReboot system
systemctl poweroffShutdown system
systemctl suspendSuspend system (sleep)
systemctl get-defaultShow default target (runlevel)
systemctl set-default multi-user.targetSet default to text mode
systemctl set-default graphical.targetSet default to GUI mode

Summary

In this comprehensive guide, you've mastered systemd service management:

✅ Understanding systemd units and service types ✅ Listing services with filters for state and type ✅ Checking detailed service status with full interpretation ✅ Starting, stopping, and restarting services effectively ✅ Enabling and disabling services for boot persistence ✅ Viewing and understanding unit file structure ✅ Analyzing service dependencies and relationships ✅ Monitoring service logs with journalctl and time filters ✅ Following best practices for service management and troubleshooting

systemd is the foundation of modern Linux service management. Mastering systemctl and journalctl commands gives you complete control over system services, enabling efficient administration, troubleshooting, and optimization.

What's Next?

Expand your systemd knowledge with these advanced topics:

  • Creating Custom Services: Write your own systemd unit files
  • Timers: Replace cron with systemd timers for scheduled tasks
  • Targets and Runlevels: Understanding system boot states
  • Resource Control: Using cgroups for CPU, memory limits
  • Socket Activation: On-demand service activation

Master systemd to manage services like a professional Linux administrator!

Owais

Written by Owais

I'm an AIOps Engineer with a passion for AI, Operating Systems, Cloud, and Security—sharing insights that matter in today's tech world.

I completed the UK's Eduqual Level 6 Diploma in AIOps from Al Nafi International College, a globally recognized program that's changing careers worldwide. This diploma is:

  • ✅ Available online in 17+ languages
  • ✅ Includes free student visa guidance for Master's programs in Computer Science fields across the UK, USA, Canada, and more
  • ✅ Comes with job placement support and a 90-day success plan once you land a role
  • ✅ Offers a 1-year internship experience letter while you study—all with no hidden costs

It's not just a diploma—it's a career accelerator.

👉 Start your journey today with a 7-day free trial

Related Articles

Continue exploring with these handpicked articles that complement what you just read

More Reading

One more article you might find interesting