> ## 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.

# Demo Working With systemctl

> Demonstration of using systemctl to view and manage systemd services including status checks, start stop restart reload enable disable mask unmask and daemon reload with sshd examples.

In this demo we'll interact directly with `systemctl` so you can see how systemd services behave in real time and how to manage them in production environments. We'll switch to the `root` user to avoid repeatedly typing `sudo` during the demo.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/9E2T0ocsNwD7Od8i/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Managing-Services/Demo-Working-With-systemctl/demo-systemctl-terminal-slide.jpg?fit=max&auto=format&n=9E2T0ocsNwD7Od8i&q=85&s=59df5f28bcbe380f49295580d3a23684" alt="A dark presentation slide titled &#x22;Demo — Working With systemctl.&#x22; On the right is a neon-blue outline icon of a terminal/command window." width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Managing-Services/Demo-Working-With-systemctl/demo-systemctl-terminal-slide.jpg" />
</Frame>

Switch to root:

```bash theme={null}
student@control:~$ su root
```

Check the status of the `sshd` service (example output shown):

```bash theme={null}
root@control:/home/student# systemctl status sshd
● sshd.service - OpenSSH server daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
     Active: active (running) since Tue 2026-04-21 11:20:19 EEST; 1min 18s ago
   Invocation: b1bc9403587544d780347be4599f69b7
     Docs: man:sshd(8)
           man:sshd_config(5)
   Main PID: 1281 (sshd)
      Tasks: 1 (limit: 23012)
     Memory: 2.3M (peak: 2.5M)
        CPU: 15ms
   CGroup: /system.slice/sshd.service
           └─1281 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Apr 21 11:20:19 control systemd[1]: Starting sshd.service - OpenSSH server daemon...
Apr 21 11:20:19 control sshd[1281]: Server listening on 0.0.0.0 port 22.
Apr 21 11:20:19 control sshd[1281]: Server listening on :: port 22.
Apr 21 11:20:19 control systemd[1]: Started sshd.service - OpenSSH server daemon.
root@control:/home/student#
```

What the important fields mean:

* `Loaded`: where the unit file comes from and its enablement status.
* `Active`: the runtime state (e.g., `active (running)`, `inactive (dead)`).
* Trailing journal-like lines: recent log messages from the service (systemd journal).

Common service lifecycle commands

* Start a service: `systemctl start <service>`
* Stop a service: `systemctl stop <service>`
* Restart a service (stop then start): `systemctl restart <service>`
* Reload service config (if supported): `systemctl reload <service>`
* Try reload, fall back to restart: `systemctl reload-or-restart <service>`

Stopping and starting services — live examples

Stop `sshd` and then check its status:

```bash theme={null}
root@control:/home/student# systemctl stop sshd
root@control:/home/student# systemctl status sshd
● sshd.service - OpenSSH server daemon
    Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
    Active: inactive (dead) since Tue 2026-04-21 11:22:00 EEST; 1s ago
   Duration: 1min 40.831s
Invocation: b1bc9403587544d780347be4599f69b7
    Docs: man:sshd(8)
          man:sshd_config(5)
   Process: 1281 ExecStart=/usr/sbin/sshd -D $OPTIONS (code=exited, status=0/SUCCESS)
    Main PID: 1281 (code=exited, status=0/SUCCESS)
    Mem peak: 2.6M
     CPU: 16ms

Apr 21 11:20:19 control systemd[1]: Starting sshd.service - OpenSSH server daemon...
Apr 21 11:20:19 control sshd[1281]: Server listening on 0.0.0.0 port 22.
Apr 21 11:20:19 control sshd[1281]: Server listening on :: port 22.
Apr 21 11:20:19 control systemd[1]: Started sshd.service - OpenSSH server daemon.
Apr 21 11:22:00 control systemd[1]: Stopping sshd.service - OpenSSH server daemon...
Apr 21 11:22:00 control sshd[1281]: Received signal 15; terminating.
Apr 21 11:22:00 control systemd[1]: sshd.service: Deactivated successfully.
Apr 21 11:22:00 control systemd[1]: Stopped sshd.service - OpenSSH server daemon.
root@control:/home/student#
```

Start `sshd` again:

```bash theme={null}
root@control:/home/student# systemctl start sshd
root@control:/home/student# systemctl status sshd
● sshd.service - OpenSSH server daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
     Active: active (running) since Tue 2026-04-21 11:22:12 EEST; 3s ago
   Invocation: 0de2759f972b4660abf0a66b7cdf99f9
     Docs: man:sshd(8)
           man:sshd_config(5)
  Main PID: 3577 (sshd)
    Tasks: 1 (limit: 23012)
   Memory: 1.3M (peak: 1.5M)
      CPU: 9ms
   CGroup: /system.slice/sshd.service
           └─3577 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Apr 21 11:22:12 control systemd[1]: Starting sshd.service - OpenSSH server daemon...
Apr 21 11:22:12 control sshd[3577]: Server listening on 0.0.0.0 port 22.
Apr 21 11:22:12 control sshd[3577]: Server listening on :: port 22.
Apr 21 11:22:12 control systemd[1]: Started sshd.service - OpenSSH server daemon.
root@control:/home/student#
```

Restart vs reload

* `systemctl restart <service>`: performs a full stop and start. Use when a full restart is acceptable (there will be downtime).
* `systemctl reload <service>`: asks the service to reload its configuration without stopping. Only works if the unit implements a reload action.
* `systemctl reload-or-restart <service>`: preferred in automation — it attempts `reload` and falls back to `restart` if reload is not supported.

<Callout icon="lightbulb" color="#1CB2FE">
  Prefer `reload` when the service supports it to avoid downtime. If `reload` is not implemented, use `restart` or `reload-or-restart` to attempt a seamless update with a fallback.
</Callout>

Enablement and script-friendly checks

* `systemctl enable <service>`: create the boot-time symlink so the service starts automatically.
* `systemctl disable <service>`: remove the boot-time symlink so the service does not start at boot.
* `systemctl is-active <service>`: returns `active`, `inactive`, etc. — useful in scripts.
* `systemctl is-enabled <service>`: returns `enabled`, `disabled`, etc. — useful in scripts.
* `systemctl list-units --type=service --state=active`: list active services; remove `--state=active` to broaden the list.

Example sequence showing reload, enable/disable and checks:

```bash theme={null}
root@control:/home/student# systemctl reload sshd
root@control:/home/student# systemctl reload-or-restart sshd
root@control:/home/student# systemctl disable sshd
Removed '/etc/systemd/system/multi-user.target.wants/sshd.service'.
root@control:/home/student# systemctl enable sshd
Created symlink '/etc/systemd/system/multi-user.target.wants/sshd.service' → '/usr/lib/systemd/system/sshd.service'.
root@control:/home/student# systemctl is-active sshd
active
root@control:/home/student# systemctl is-enabled sshd
enabled
root@control:/home/student# systemctl list-units --type=service --state=active
```

Quick reference: common systemctl commands

| Action | Command example | Description |
| - | - | - |
| Start service | `systemctl start sshd` | Start immediately |
| Stop service | `systemctl stop sshd` | Stop immediately |
| Restart service | `systemctl restart sshd` | Stop then start (downtime) |
| Reload config | `systemctl reload sshd` | Reload configuration without stop (if supported) |
| Reload or restart | `systemctl reload-or-restart sshd` | Try reload, fallback to restart |
| Enable at boot | `systemctl enable sshd` | Start on boot |
| Disable at boot | `systemctl disable sshd` | Don't start on boot |
| Mask service | `systemctl mask sshd` | Prevent any form of start |
| Unmask service | `systemctl unmask sshd` | Restore ability to start |
| Check runtime state | `systemctl is-active sshd` | `active` / `inactive` |
| Check enablement | `systemctl is-enabled sshd` | `enabled` / `disabled` |

Masking and unmasking services

* Masking creates a symlink from the unit file path to `/dev/null`, preventing the unit from being started manually or as a dependency.
* To start a masked service you must first `unmask` it.

Example:

```bash theme={null}
root@control:/home/student# systemctl stop sshd
root@control:/home/student# systemctl mask sshd
Created symlink '/etc/systemd/system/sshd.service' → '/dev/null'.
root@control:/home/student# systemctl start sshd
Failed to start sshd.service: Unit sshd.service is masked.
root@control:/home/student# systemctl unmask sshd
Removed '/etc/systemd/system/sshd.service'.
root@control:/home/student# systemctl start sshd
root@control:/home/student# systemctl daemon-reload
```

Important: after editing or adding unit files, run `systemctl daemon-reload` so systemd re-reads unit definitions.

Further reading and references

* systemd man pages: `man systemd`, `man systemctl`
* OpenSSH: `man sshd`, `man sshd_config`
* Official systemd documentation: [https://www.freedesktop.org/wiki/Software/systemd/](https://www.freedesktop.org/wiki/Software/systemd/) and [https://www.freedesktop.org/software/systemd/man/systemctl.html](https://www.freedesktop.org/software/systemd/man/systemctl.html)

This concludes the demo on interacting with `systemctl` and managing services in real time.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/red-hat-certified-system-administrator-rhcsa/module/1174f490-60ba-47e8-a425-bcb43f569712/lesson/841691db-a9f5-4388-9679-cf3a288979f2" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/red-hat-certified-system-administrator-rhcsa/module/1174f490-60ba-47e8-a425-bcb43f569712/lesson/d7f4764f-2fed-47a9-b36e-88b98f47830a" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.