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 ██ 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 2 / 15
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 3 / 15
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 4 / 15
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 5 / 15
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 6 / 15
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 7 / 15
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 8 / 15
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 9 / 15
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 10 / 15
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 11 / 15
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 12 / 15
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 13 / 15
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 14 / 15
Thank you! Thank you for your attention! Don't forget the feedback in Moodle please! Introduction to Linux: Services and Remote Access 15 / 15