Skip to main content
In this guide, you’ll learn how to inspect, configure, and control services on a Linux system using systemd—the modern init system. We cover unit files, service management commands, and best practices for maintaining your server’s services.

Table of Contents

  1. Introduction to systemd
  2. Unit File Types
  3. Service Unit Structure
  4. Inspecting the SSH Daemon Service
  5. Editing and Reverting a Unit
  6. Monitoring Service Status
  7. Managing Service Lifecycle
  8. Enabling and Disabling at Boot
  9. Masking and Unmasking Services
  10. Listing All Service Units
  11. Further Reading

Introduction to systemd

When Linux boots, systemd orchestrates service startup in parallel while respecting dependencies. If a critical service fails, systemd can restart it automatically, ensuring high availability. All behavior is defined by unit files—plain-text configurations that tell systemd how to manage resources.
Learn more about systemd on the Official Freedesktop Wiki.

Unit File Types

Unit files end in .service, .socket, .device, .timer, and more. Here’s a quick overview:

Service Unit Structure

Service units reside in /etc/systemd/system/ or /usr/lib/systemd/system/. They have three main sections:
Key directives:
  • ExecStart: Command to launch the service
  • ExecReload: How to reload without a full restart
  • Restart: Policy (no, on-failure, always)
Consult the manual for all options:

Inspecting the SSH Daemon Service

Most servers run the OpenSSH daemon (sshd) as a systemd service. View its complete unit file:

Editing and Reverting a Unit

To fully edit the sshd.service file:
To discard changes and restore the vendor-provided unit:

Monitoring Service Status

Check detailed status and recent logs:
Sample output:
Press Q to exit.

Managing Service Lifecycle

Use systemctl for day-to-day operations:

Enabling and Disabling at Boot

Control automatic startup:
Combine with --now to apply immediately:
Disabling and stopping sshd.service will prevent all SSH logins.

Masking and Unmasking Services

Prevent any activation—manual or dependency-driven—by masking:
Reverse masking:
Attempting to start a masked service results in:

Listing All Service Units

View every service, regardless of state:

Further Reading

Watch Video

Practice Lab