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.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Table of Contents
- Introduction to systemd
- Unit File Types
- Service Unit Structure
- Inspecting the SSH Daemon Service
- Editing and Reverting a Unit
- Monitoring Service Status
- Managing Service Lifecycle
- Enabling and Disabling at Boot
- Masking and Unmasking Services
- Listing All Service Units
- 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:
| Unit Type | Description |
|---|---|
| service | Defines how to start, stop, and manage a service |
| socket | Configures socket activation |
| target | Groups units and handles synchronization |
| timer | Schedules tasks similar to cron |
Service Unit Structure
Service units reside in/etc/systemd/system/ or /usr/lib/systemd/system/. They have three main sections:
- ExecStart: Command to launch the service
- ExecReload: How to reload without a full restart
- Restart: Policy (
no,on-failure,always)
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 thesshd.service file:
Monitoring Service Status
Check detailed status and recent logs:Q to exit.
Managing Service Lifecycle
Usesystemctl for day-to-day operations:
| Operation | Command | Description |
|---|---|---|
| Start | sudo systemctl start sshd.service | Launch the service immediately |
| Stop | sudo systemctl stop sshd.service | Stop the service |
| Restart | sudo systemctl restart sshd.service | Stop and then start the service |
| Reload | sudo systemctl reload sshd.service | Reload configuration without full restart |
| Reload or Restart | sudo systemctl reload-or-restart sshd.service | Try reload, else restart |
Enabling and Disabling at Boot
Control automatic startup:--now to apply immediately:
Disabling and stopping
sshd.service will prevent all SSH logins.