Introduction to Linux: Services and Remote Access
Philipp Fruck & Pius Walter System Services and Remote Systems ██ Goal of this Lecture • How to run persistent, scheduled and background services • How to inspect logs, analyze failures & perform troubleshooting • How to securely connect to remote systems • How Linux manages networking and DNS • How to sandbox services with systemd Introduction to Linux: Services and Remote Access 2 / 54
System Services and Remote Systems ██ Goal of this Lecture • How to run persistent, scheduled and background services • How to inspect logs, analyze failures & perform troubleshooting • How to securely connect to remote systems • How Linux manages networking and DNS • How to sandbox services with systemd ██ Why? • 90 % of infrastructure runs on headless Linux servers • You must control systems without a GUI, even during incidents • Understanding services & logs is key for: ◦ intrusion detection ◦ forensic analysis ◦ disaster recovery Introduction to Linux: Services and Remote Access 3 / 54
systemd: Service Management Start/Stop/Enable sudo systemctl start nginx
sudo systemctl enable nginx
# hard restart (drop connections)
sudo systemctl restart nginx
# or soft reload (keep connections)
sudo systemctl reload nginx
Introduction to Linux: Services and Remote Access 4 / 54
systemd: Service Management Start/Stop/Enable sudo systemctl start nginx
sudo systemctl enable nginx
# hard restart (drop connections)
sudo systemctl restart nginx
# or soft reload (keep connections)
sudo systemctl reload nginx
Shortcuts: # combine start and enable
systemctl [enable|disable] --now ...
# show logs (new since systemd 258)
systemctl [start|stop|restart] -v ...
Introduction to Linux: Services and Remote Access 5 / 54
systemd: Service Management Start/Stop/Enable Check status
sudo systemctl start nginx systemctl status sshd
sudo systemctl enable nginx systemctl status --user pipewire
# hard restart (drop connections)
sudo systemctl restart nginx
# or soft reload (keep connections)
sudo systemctl reload nginx
Shortcuts: # combine start and enable
systemctl [enable|disable] --now ...
# show logs (new since systemd 258)
systemctl [start|stop|restart] -v ...
Introduction to Linux: Services and Remote Access 6 / 54
systemd: Service Management Start/Stop/Enable Check status
sudo systemctl start nginx systemctl status sshd
sudo systemctl enable nginx systemctl status --user pipewire
# hard restart (drop connections)
sudo systemctl restart nginx
# or soft reload (keep connections) List failed services
sudo systemctl reload nginx
systemctl list-units --failed
Shortcuts:
# combine start and enable
systemctl [enable|disable] --now ...
# show logs (new since systemd 258)
systemctl [start|stop|restart] -v ...
Introduction to Linux: Services and Remote Access 7 / 54
systemd: Service Management Start/Stop/Enable Check status
sudo systemctl start nginx systemctl status sshd
sudo systemctl enable nginx systemctl status --user pipewire
# hard restart (drop connections)
sudo systemctl restart nginx
# or soft reload (keep connections) List failed services
sudo systemctl reload nginx
systemctl list-units --failed
Shortcuts:
Analyze boot time
# combine start and enable
systemctl [enable|disable] --now ...
# show logs (new since systemd 258) systemd-analyze
systemctl [start|stop|restart] -v ... systemd-analyze blame
systemd-analyze critical-chain
Introduction to Linux: Services and Remote Access 8 / 54
systemd: Service Unit Basics Example: /etc/systemd/system/example.service
[Unit]
Description=Example App
[Service]
ExecStart=/usr/local/bin/app
Restart=always
User=appuser
[Install]
#WantedBy=graphical.target # GUI ready
#WantedBy=multi-user.target # CLI ready
WantedBy=default.target # GUI or CLI
#WantedBy=network.target # network ready
Introduction to Linux: Services and Remote Access 9 / 54
systemd: Service Unit Basics Example: /etc/systemd/system/example.service ██ User vs System scope
• system: /etc/systemd/system/
[Unit] • user: ~/.config/systemd/user/
Description=Example App
[Service]
ExecStart=/usr/local/bin/app
Restart=always
User=appuser
[Install]
#WantedBy=graphical.target # GUI ready
#WantedBy=multi-user.target # CLI ready
WantedBy=default.target # GUI or CLI
#WantedBy=network.target # network ready
Introduction to Linux: Services and Remote Access 10 / 54
systemd: Service Unit Basics Example: /etc/systemd/system/example.service ██ User vs System scope
• system: /etc/systemd/system/
[Unit] • user: ~/.config/systemd/user/
Description=Example App
Enable and run
[Service]
ExecStart=/usr/local/bin/app
Restart=always sudo systemctl [--user] daemon-reload
User=appuser sudo systemctl [--user] enable --now example.service
[Install]
#WantedBy=graphical.target # GUI ready
#WantedBy=multi-user.target # CLI ready
WantedBy=default.target # GUI or CLI
#WantedBy=network.target # network ready
Introduction to Linux: Services and Remote Access 11 / 54
systemd: Service Unit Basics Example: /etc/systemd/system/example.service ██ User vs System scope
• system: /etc/systemd/system/
[Unit] • user: ~/.config/systemd/user/
Description=Example App
Enable and run
[Service]
ExecStart=/usr/local/bin/app
Restart=always sudo systemctl [--user] daemon-reload
User=appuser sudo systemctl [--user] enable --now example.service
[Install]
#WantedBy=graphical.target # GUI ready Dependencies
#WantedBy=multi-user.target # CLI ready
WantedBy=default.target # GUI or CLI
#WantedBy=network.target # network ready [Unit]
# start serviceA when starting serviceB.
Requires=serviceA.service
# ensure serviceA is fully started.
After=serviceA.service
Introduction to Linux: Services and Remote Access 12 / 54
journalctl: Viewing Logs System log viewer (replaces many legacy tools like dmesg and /var/log/*)
Basic usage journalctl -u sshd.service
journalctl -b # since boot
journalctl -b 1 # since first boot
journalctl -b -1 # since last boot
journalctl -f # live follow
# commonly used: eXplain, End, Follow
journalctl [--user] -xefu <unit>
Introduction to Linux: Services and Remote Access 13 / 54
journalctl: Viewing Logs System log viewer (replaces many legacy tools like dmesg and /var/log/*)
Basic usage Filter by user
journalctl -u sshd.service journalctl _UID=1000
journalctl -b # since boot
journalctl -b 1 # since first boot
journalctl -b -1 # since last boot
journalctl -f # live follow
# commonly used: eXplain, End, Follow
journalctl [--user] -xefu <unit>
Introduction to Linux: Services and Remote Access 14 / 54
journalctl: Viewing Logs System log viewer (replaces many legacy tools like dmesg and /var/log/*)
Basic usage Filter by user
journalctl -u sshd.service journalctl _UID=1000
journalctl -b # since boot
journalctl -b 1 # since first boot
journalctl -b -1 # since last boot
journalctl -f # live follow # equivalent to sudo dmesg --ctime
# commonly used: eXplain, End, Follow sudo journalctl -ke
journalctl [--user] -xefu <unit> # equivalent to
# sudo cat /var/log/audit/audit.log
sudo journalctl -t audit \
--no-pager --output=cat
Introduction to Linux: Services and Remote Access 15 / 54
SSH: Server, Keys and Permissions Server config: /etc/ssh/sshd_config
PasswordAuthentication no
PermitRootLogin no
Port 22
Introduction to Linux: Services and Remote Access 16 / 54
SSH: Server, Keys and Permissions Server config: /etc/ssh/sshd_config
PasswordAuthentication no
PermitRootLogin no
Port 22
Apply changes sudo sshd -t # ensure valid config!
sudo systemctl reload sshd # keep sessions
sudo systemctl restart sshd # drop sessions
Introduction to Linux: Services and Remote Access 17 / 54
SSH: Server, Keys and Permissions Server config: /etc/ssh/sshd_config
PasswordAuthentication no
PermitRootLogin no
Port 22
Apply changes sudo sshd -t # ensure valid config!
sudo systemctl reload sshd # keep sessions
sudo systemctl restart sshd # drop sessions
Generate and copy key pair ssh-keygen -t ed25519 -C "you@hostname"
ssh-copy-id user@host
Introduction to Linux: Services and Remote Access 18 / 54
SSH: Server, Keys and Permissions Server config: /etc/ssh/sshd_config Permissions matter!
File │ Permissions
PasswordAuthentication no ───────────────────────┼────────────
PermitRootLogin no ~/.ssh │ 700
Port 22 ~/.ssh/authorized_keys │ 600
~/.ssh/id_* │ 600
Apply changes
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
sudo sshd -t # ensure valid config!
sudo systemctl reload sshd # keep sessions
sudo systemctl restart sshd # drop sessions
Generate and copy key pair ssh-keygen -t ed25519 -C "you@hostname"
ssh-copy-id user@host
Introduction to Linux: Services and Remote Access 19 / 54
SSH: Server, Keys and Permissions Server config: /etc/ssh/sshd_config Permissions matter!
File │ Permissions
PasswordAuthentication no ───────────────────────┼────────────
PermitRootLogin no ~/.ssh │ 700
Port 22 ~/.ssh/authorized_keys │ 600
~/.ssh/id_* │ 600
Apply changes
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
sudo sshd -t # ensure valid config!
sudo systemctl reload sshd # keep sessions
sudo systemctl restart sshd # drop sessions ~/.ssh/authorized_keys holds the public keys that are
authorized to log in as the given user.
Generate and copy key pair ssh-copy-id is a shortcut for running e.g.
ssh-keygen -t ed25519 -C "you@hostname" echo "ssh-ed25519 AAAA.... mypubkey" \
ssh-copy-id user@host >> ~/.ssh/authorized_keys
Introduction to Linux: Services and Remote Access 20 / 54
SSH: Server, Keys and Permissions Server config: /etc/ssh/sshd_config Permissions matter!
File │ Permissions
PasswordAuthentication no ───────────────────────┼────────────
PermitRootLogin no ~/.ssh │ 700
Port 22 ~/.ssh/authorized_keys │ 600
~/.ssh/id_* │ 600
Apply changes
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
sudo sshd -t # ensure valid config!
sudo systemctl reload sshd # keep sessions
sudo systemctl restart sshd # drop sessions ~/.ssh/authorized_keys holds the public keys that are
authorized to log in as the given user.
Generate and copy key pair ssh-copy-id is a shortcut for running e.g.
ssh-keygen -t ed25519 -C "you@hostname" echo "ssh-ed25519 AAAA.... mypubkey" \
ssh-copy-id user@host >> ~/.ssh/authorized_keys
▍ Use SSH key authentication over passwords!
Introduction to Linux: Services and Remote Access 21 / 54
SSH: Jump Hosts and Port Forwarding ██ Jump Hosts (ProxyJump) For hosts only reachable via another host ssh -J user@jump.example.com user@target
Introduction to Linux: Services and Remote Access 22 / 54
SSH: Jump Hosts and Port Forwarding ██ Jump Hosts (ProxyJump) For hosts only reachable via another host ssh -J user@jump.example.com user@target
Permanent config: ~/.ssh/config
Host internal
HostName 10.0.0.5
ProxyJump jump.example.com
ssh internal
Introduction to Linux: Services and Remote Access 23 / 54
SSH: Jump Hosts and Port Forwarding ██ Jump Hosts (ProxyJump) ██ Port Forwarding
For hosts only reachable via another host Local: expose a remote service locally
ssh -J user@jump.example.com user@target ssh -L 8080:localhost:80 user@host
Permanent config: ~/.ssh/config
Host internal
HostName 10.0.0.5
ProxyJump jump.example.com
ssh internal
Introduction to Linux: Services and Remote Access 24 / 54
SSH: Jump Hosts and Port Forwarding ██ Jump Hosts (ProxyJump) ██ Port Forwarding
For hosts only reachable via another host Local: expose a remote service locally
ssh -J user@jump.example.com user@target ssh -L 8080:localhost:80 user@host
Permanent config: ~/.ssh/config Remote: expose your local service remotely
Host internal ssh -R 2222:localhost:22 user@host
HostName 10.0.0.5
ProxyJump jump.example.com
ssh internal
Introduction to Linux: Services and Remote Access 25 / 54
SSH: Jump Hosts and Port Forwarding ██ Jump Hosts (ProxyJump) ██ Port Forwarding
For hosts only reachable via another host Local: expose a remote service locally
ssh -J user@jump.example.com user@target ssh -L 8080:localhost:80 user@host
Permanent config: ~/.ssh/config Remote: expose your local service remotely
Host internal ssh -R 2222:localhost:22 user@host
HostName 10.0.0.5
ProxyJump jump.example.com
SOCKS5 proxy: full encrypted tunnel
ssh internal ssh -D 1080 user@host
Introduction to Linux: Services and Remote Access 26 / 54
tmux: Terminal Multiplexing Persistent sessions which survive disconnects • Split terminal into panes • Shared sessions for teamwork Introduction to Linux: Services and Remote Access 27 / 54
tmux: Terminal Multiplexing Persistent sessions which survive disconnects • Split terminal into panes • Shared sessions for teamwork Basic usage tmux # start
tmux ls # list sessions
tmux attach -t <id> # reattach
Introduction to Linux: Services and Remote Access 28 / 54
tmux: Terminal Multiplexing Persistent sessions which survive disconnects Basic keys (press Ctrl+B first)
• Split terminal into panes Action │ Keys
• Shared sessions for teamwork ───────────────────┼─────
Split vertically │ %
Basic usage Split horizontally │ "
New window │ c
Switch windows │ 0-9
tmux # start Detach session │ d
tmux ls # list sessions
tmux attach -t <id> # reattach
Introduction to Linux: Services and Remote Access 29 / 54
tmux: Terminal Multiplexing Persistent sessions which survive disconnects Basic keys (press Ctrl+B first)
• Split terminal into panes Action │ Keys
• Shared sessions for teamwork ───────────────────┼─────
Split vertically │ %
Basic usage Split horizontally │ "
New window │ c
Switch windows │ 0-9
tmux # start Detach session │ d
tmux ls # list sessions
tmux attach -t <id> # reattach
Activate mouse mode by pressing Ctrl+B and : then entering set -g mouse on.
Introduction to Linux: Services and Remote Access 30 / 54
Networking ██ Modern • NetworkManager.service (e.g. on Fedora)
◦ nmcli/nmtui on the CLI
• systemd-networkd.service
◦ Relies on config files ◦ More suitable for servers Introduction to Linux: Services and Remote Access 31 / 54
Networking ██ Modern • NetworkManager.service (e.g. on Fedora)
◦ nmcli/nmtui on the CLI
• systemd-networkd.service
◦ Relies on config files ◦ More suitable for servers ██ Traditional • networking.service (e.g. Debian)
◦ Uses /etc/network/interfaces
Introduction to Linux: Services and Remote Access 32 / 54
Networking ██ Modern • NetworkManager.service (e.g. on Fedora)
◦ nmcli/nmtui on the CLI
• systemd-networkd.service
◦ Relies on config files ◦ More suitable for servers ██ Traditional • networking.service (e.g. Debian)
◦ Uses /etc/network/interfaces
██ Ubuntu • Netplan abstraction layer ◦ NetworkManager for GUI ◦ systemd-networkd for server Introduction to Linux: Services and Remote Access 33 / 54
Networking ██ Modern ██ Universal
• NetworkManager.service (e.g. on Fedora) IP command is universal, but not persistent
◦ nmcli/nmtui on the CLI
• systemd-networkd.service
◦ Relies on config files # Address Add
◦ More suitable for servers ip a a 192.168.7.42 dev enp0s1
# Address Delete
██ Traditional ip a d 192.168.7.42 dev enp0s1
• networking.service (e.g. Debian)
◦ Uses /etc/network/interfaces
██ Ubuntu • Netplan abstraction layer ◦ NetworkManager for GUI ◦ systemd-networkd for server Introduction to Linux: Services and Remote Access 34 / 54
Networking ██ Modern ██ Universal
• NetworkManager.service (e.g. on Fedora) IP command is universal, but not persistent
◦ nmcli/nmtui on the CLI
• systemd-networkd.service
◦ Relies on config files # Address Add
◦ More suitable for servers ip a a 192.168.7.42 dev enp0s1
# Address Delete
██ Traditional ip a d 192.168.7.42 dev enp0s1
• networking.service (e.g. Debian)
◦ Uses /etc/network/interfaces ██ Naming
██ Ubuntu • Traditional names: eth0, eth1, ...
• systemd naming scheme (enp0s1):
• Netplan abstraction layer ◦ en = Ethernet, wl = Wi-Fi
◦ NetworkManager for GUI ◦ s = slot, u = port
◦ systemd-networkd for server ◦ man systemd.net-naming-scheme
Introduction to Linux: Services and Remote Access 35 / 54
DNS ██ Traditional /etc/resolv.conf
Plain text file storing DNS servers and search domains: nameserver 1.1.1.1
search example.com
• Managed manually or by scripts ◦ e.g. ifup/dhclient
• Applications read it directly Introduction to Linux: Services and Remote Access 36 / 54
DNS ██ Traditional /etc/resolv.conf ██ systemd-resolved
Plain text file storing DNS servers and • systemd service providing DNS resolution
search domains: • resolvectl status
• Maintains its own dynamic DNS configuration • /etc/resolv.conf is usually a symlink to
nameserver 1.1.1.1 ◦ /run/systemd/resolve/stub-resolv.conf
search example.com ▪ uses 127.0.0.53 as local DNS stub
◦ Or /run/systemd/resolve/resolv.conf
▪ full configuration • Managed manually or by scripts • Benefits:
◦ e.g. ifup/dhclient ◦ Support multiple interfaces with different DNS
• Applications read it directly ◦ Provides caching
Introduction to Linux: Services and Remote Access 37 / 54
DNS ██ Traditional /etc/resolv.conf ██ systemd-resolved
Plain text file storing DNS servers and • systemd service providing DNS resolution
search domains: • resolvectl status
• Maintains its own dynamic DNS configuration • /etc/resolv.conf is usually a symlink to
nameserver 1.1.1.1 ◦ /run/systemd/resolve/stub-resolv.conf
search example.com ▪ uses 127.0.0.53 as local DNS stub
◦ Or /run/systemd/resolve/resolv.conf
▪ full configuration • Managed manually or by scripts • Benefits:
◦ e.g. ifup/dhclient ◦ Support multiple interfaces with different DNS
• Applications read it directly ◦ Provides caching
Key Difference: /etc/resolv.conf is static, whereas systemd-resolved is a dynamic DNS resolver that updates /etc/resolv.conf or provides a
local stub for applications. Introduction to Linux: Services and Remote Access 38 / 54
Scheduled Tasks ██ Traditional: Cron crontab -e # edit
crontab -l # list
┌─────── minute (0 - 59)
│ ┌─────── hour (0 - 23)
│ │ ┌─────── day of month (1 - 31)
│ │ │ ┌─────── month (1 - 12)
│ │ │ │ ┌─────── day of week (0 - 7)
│ │ │ │ │ (Sunday=0 or 7)
* * * * * command_to_run
Introduction to Linux: Services and Remote Access 39 / 54
Scheduled Tasks ██ Traditional: Cron crontab -e # edit
crontab -l # list
┌─────── minute (0 - 59)
│ ┌─────── hour (0 - 23)
│ │ ┌─────── day of month (1 - 31)
│ │ │ ┌─────── month (1 - 12)
│ │ │ │ ┌─────── day of week (0 - 7)
│ │ │ │ │ (Sunday=0 or 7)
* * * * * command_to_run
Q: How do we define a nightly backup job at 4 AM?
Introduction to Linux: Services and Remote Access 40 / 54
Scheduled Tasks ██ Traditional: Cron crontab -e # edit
crontab -l # list
┌─────── minute (0 - 59)
│ ┌─────── hour (0 - 23)
│ │ ┌─────── day of month (1 - 31)
│ │ │ ┌─────── month (1 - 12)
│ │ │ │ ┌─────── day of week (0 - 7)
│ │ │ │ │ (Sunday=0 or 7)
* * * * * command_to_run
Q: How do we define a nightly backup job at 4 AM?
A: 0 4 * * * backup.sh
Introduction to Linux: Services and Remote Access 41 / 54
Scheduled Tasks ██ Traditional: Cron ██ Modern: systemd timers
• Name indicates which service to start
crontab -e # edit ◦ foo.timer triggers foo.service
crontab -l # list • e.g. /etc/systemd/system/myservice.timer
[Unit]
┌─────── minute (0 - 59) Description=Runs myservice.service
│ ┌─────── hour (0 - 23) [Timer]
│ │ ┌─────── day of month (1 - 31) # Run 5min after system has booted
│ │ │ ┌─────── month (1 - 12) OnBootSec=5m
│ │ │ │ ┌─────── day of week (0 - 7) # Run every hour
│ │ │ │ │ (Sunday=0 or 7) OnCalendar=hourly
* * * * * command_to_run [Install]
WantedBy=timers.target
Q: How do we define a nightly backup job at 4 AM?
A: 0 4 * * * backup.sh systemctl list-timers
Introduction to Linux: Services and Remote Access 42 / 54
Scheduled Tasks ██ Traditional: Cron ██ Modern: systemd timers
• Name indicates which service to start
crontab -e # edit ◦ foo.timer triggers foo.service
crontab -l # list • e.g. /etc/systemd/system/myservice.timer
[Unit]
┌─────── minute (0 - 59) Description=Runs myservice.service
│ ┌─────── hour (0 - 23) [Timer]
│ │ ┌─────── day of month (1 - 31) # Run 5min after system has booted
│ │ │ ┌─────── month (1 - 12) OnBootSec=5m
│ │ │ │ ┌─────── day of week (0 - 7) # Run every hour
│ │ │ │ │ (Sunday=0 or 7) OnCalendar=hourly
* * * * * command_to_run [Install]
WantedBy=timers.target
Q: How do we define a nightly backup job at 4 AM?
A: 0 4 * * * backup.sh systemctl list-timers
▍ Preference: systemd timers -> better logging, dependency handling, boot triggers
Introduction to Linux: Services and Remote Access 43 / 54
Hardening Services: systemd-analyze security
Services often run as root with full system access. systemd can sandbox them without changing the application.
# exposure overview of all running services
systemd-analyze security
# detailed report for a single unit
systemd-analyze security sshd.service
Introduction to Linux: Services and Remote Access 44 / 54
Hardening Services: systemd-analyze security
Services often run as root with full system access. systemd can sandbox them without changing the application.
# exposure overview of all running services
systemd-analyze security
# detailed report for a single unit
systemd-analyze security sshd.service
• Each setting contributes to an exposure level from 0.0 (safe) to 10.0 (UNSAFE)
• ✓ = restricted, ✗ = exposed • The score is a hint, not a guarantee: e.g. sshd legitimately needs a lot of access
Introduction to Linux: Services and Remote Access 45 / 54
Hardening Services: systemd-analyze security
Services often run as root with full system access. systemd can sandbox them without changing the application.
# exposure overview of all running services
systemd-analyze security
# detailed report for a single unit
systemd-analyze security sshd.service
• Each setting contributes to an exposure level from 0.0 (safe) to 10.0 (UNSAFE)
• ✓ = restricted, ✗ = exposed • The score is a hint, not a guarantee: e.g. sshd legitimately needs a lot of access
An analysis of NowNewPrivileges for Debian packages:
▍ https://media.ccc.de/v/all-systems-go-2026-400-the-state-of-systemd-sandboxing-in-debian
Introduction to Linux: Services and Remote Access 46 / 54
Hardening Services: Directives Add to the [Service] section
[Service]
DynamicUser=yes
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
CapabilityBoundingSet=
RestrictAddressFamilies=AF_INET AF_INET6
SystemCallFilter=@system-service
Introduction to Linux: Services and Remote Access 47 / 54
Hardening Services: Directives Add to the [Service] section Directive │ Effect
────────────────────────┼───────────────────────────────── DynamicUser │ Temporary unprivileged user
[Service] NoNewPrivileges │ Blocks setuid escalation
DynamicUser=yes ProtectSystem=strict │ File system is read-only
NoNewPrivileges=yes ProtectHome │ /home is inaccessible
ProtectSystem=strict PrivateTmp │ Own, isolated /tmp
ProtectHome=yes CapabilityBoundingSet= │ Drops all capabilities
PrivateTmp=yes RestrictAddressFamilies │ Limits socket types
PrivateDevices=yes SystemCallFilter │ Allow-list of syscalls (seccomp)
CapabilityBoundingSet=
RestrictAddressFamilies=AF_INET AF_INET6
SystemCallFilter=@system-service
Introduction to Linux: Services and Remote Access 48 / 54
Hardening Services: Directives Add to the [Service] section Directive │ Effect
────────────────────────┼───────────────────────────────── DynamicUser │ Temporary unprivileged user
[Service] NoNewPrivileges │ Blocks setuid escalation
DynamicUser=yes ProtectSystem=strict │ File system is read-only
NoNewPrivileges=yes ProtectHome │ /home is inaccessible
ProtectSystem=strict PrivateTmp │ Own, isolated /tmp
ProtectHome=yes CapabilityBoundingSet= │ Drops all capabilities
PrivateTmp=yes RestrictAddressFamilies │ Limits socket types
PrivateDevices=yes SystemCallFilter │ Allow-list of syscalls (seccomp)
CapabilityBoundingSet=
RestrictAddressFamilies=AF_INET AF_INET6
SystemCallFilter=@system-service
▍ Use systemctl edit <unit> to add hardening via a drop-in without touching the vendor unit file.
Introduction to Linux: Services and Remote Access 49 / 54
Exercise 1. List the exposure of all services: systemd-analyze security
2. Find the most exposed service and inspect it: systemd-analyze security <unit>
Introduction to Linux: Services and Remote Access 50 / 54
Exercise 1. List the exposure of all services: systemd-analyze security
2. Find the most exposed service and inspect it: systemd-analyze security <unit>
3. Create a service /etc/systemd/system/hello.service which runs /usr/bin/sleep 600
4. Check its score with systemd-analyze security hello.service
Introduction to Linux: Services and Remote Access 51 / 54
Exercise 1. List the exposure of all services: systemd-analyze security
2. Find the most exposed service and inspect it: systemd-analyze security <unit>
3. Create a service /etc/systemd/system/hello.service which runs /usr/bin/sleep 600
4. Check its score with systemd-analyze security hello.service
5. Add hardening directives with systemctl edit hello.service until the score drops below 3.0
6. Restart the unit, then check systemctl status hello and journalctl -u hello
Introduction to Linux: Services and Remote Access 52 / 54
Exercise 1. List the exposure of all services: systemd-analyze security
2. Find the most exposed service and inspect it: systemd-analyze security <unit>
3. Create a service /etc/systemd/system/hello.service which runs /usr/bin/sleep 600
4. Check its score with systemd-analyze security hello.service
5. Add hardening directives with systemctl edit hello.service until the score drops below 3.0
6. Restart the unit, then check systemctl status hello and journalctl -u hello
Bonus: Try the directives ad hoc without a unit file systemd-run -p ProtectSystem=strict -p PrivateTmp=yes --pty bash
Introduction to Linux: Services and Remote Access 53 / 54
Thank you! Thank you for your attention! Don't forget the feedback in Moodle please! Introduction to Linux: Services and Remote Access 54 / 54