Skip to main content
Linux Processes, systemd Sandboxing & auditd Logs
Lesson 2 of 12

Linux Processes, systemd Sandboxing & auditd Logs

Inspect running Linux processes, lock down systemd services using sandboxing directives and systemd-analyze security, and trace suspicious activity with auditctl and ausearch.

Intermediate 26 min Linux & Windows
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Inspect process ownership, parent-child relationships, and listening sockets on a Linux host
  • Evaluate a systemd service's exposure with systemd-analyze security and apply sandboxing drop-ins
  • Create file-watch and syscall audit rules using auditctl with searchable keys
  • Correlate auditd SYSCALL, EXECVE, and PATH records using ausearch to identify who triggered an action

Recommended first: Linux Fundamentals Recap: ACLs, PAM & SSH Hardening

#Why this matters

Even with tight file permissions and hardened SSH access, a compromised daemon running as root with full filesystem access can read credentials, modify binaries, and plant persistence. Isolating services limits what a hijacked process can touch, while kernel-level auditing records what actually happened when an intrusion occurs.

Combining systemd sandboxing with auditd closes both gaps: you shrink each service's blast radius before an attack and leave tamper-resistant forensic breadcrumbs if one succeeds.

#Inspecting processes and service exposure

Every running process carries an effective user ID (euid), a parent process ID (ppid), and a set of Linux capabilities. Before tightening a service, inspect what runs, who owns it, and which ports it binds:

Checking processes, sockets, and unit exposure
$ ps -eo pid,ppid,user,euid,comm --sort=-pid | head -n 6
  PID  PPID USER  EUID COMMAND
 2418     1 www-data 33 report-api
 2305     1 root     0 sshd
$ ss -tulpn | grep 8080
tcp   LISTEN 0  128  127.0.0.1:8080  0.0.0.0:*  users:(("report-api",pid=2418,fd=6))
$ systemd-analyze security report-api.service | tail -n 3
-> Overall exposure level for report-api.service: 9.2 UNSAFE

A score near 10.0 (UNSAFE) means the unit runs largely unrestricted. Even if User=reportsvc is set, the process can still see /home, potentially probe /etc or /tmp, or execute SUID helpers unless sandboxed.

#Sandboxing services with systemd drop-ins

Never edit vendor unit files in /usr/lib/systemd/system/ directly; package updates overwrite them. Instead, create a drop-in override using systemctl edit report-api.service, which writes to /etc/systemd/system/report-api.service.d/override.conf:

ini
[Service]
User=reportsvc
NoNewPrivileges=yes
PrivateTmp=yes
ProtectHome=yes
ProtectSystem=strict
ReadWritePaths=/var/lib/report-api
CapabilityBoundingSet=
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
Directive Effect on the running service
NoNewPrivileges=yes Blocks SUID/SGID and file-capability privilege escalation
PrivateTmp=yes Mounts isolated /tmp and /var/tmp directories for the unit
ProtectHome=yes Makes /home, /root, and /run/user inaccessible
ProtectSystem=strict Mounts the whole filesystem read-only except /dev, /proc, /sys
ReadWritePaths=... Re-grants write access strictly to the service's data directory
CapabilityBoundingSet= Drops all Linux capabilities when left empty

Reload and re-check the exposure score after applying the drop-in:

bash
sudo systemctl daemon-reload
sudo systemctl restart report-api.service
systemd-analyze security report-api.service

Always pair service sandboxing with journalctl -u report-api.service -n 30 right after restarting so you catch legitimate permission denials before moving on.

#Kernel auditing with auditd and auditctl

Standard application logs tell you what a program chose to print; auditd logs what the kernel observed in /var/log/audit/audit.log. Rules are managed temporarily with auditctl and persisted in /etc/audit/rules.d/*.rules (applied via augenrules --load).

Two rule styles cover most investigations:

  1. File watches (-w): track reads, writes, executions, or attribute changes (-p rwxa) on sensitive paths.
  2. Syscall rules (-a): trigger when specific system calls finish, filtered by architecture, UID, or exit status.
Adding temporary audit rules for testing
$ sudo auditctl -w /etc/ssh/sshd_config -p wa -k sshd_cfg
$ sudo auditctl -a always,exit -F arch=b64 -S execve -F euid=0 -k root_exec
$ sudo auditctl -l
-w /etc/ssh/sshd_config -p wa -k sshd_cfg
-a always,exit -F arch=b64 -S execve -F euid=0 -k root_exec
  1. auditctl ruleKernel audit hook | /var/log/audit/audit.log | ausearch -k <key> -i

#Reading audit records with ausearch

Raw audit.log lines store epoch timestamps and numeric IDs. Pass -i (interpret) to ausearch to decode timestamps, usernames, and syscall names, and -k to match a rule key:

Querying an event by audit key
$ sudo ausearch -k sshd_cfg -i | tail -n 6
----
type=PROCTITLE msg=audit(11/18/2026 14:22:09.314:412) : proctitle=vi /etc/ssh/sshd_config
type=PATH msg=audit(11/18/2026 14:22:09.314:412) : item=0 name=/etc/ssh/sshd_config inode=131098 ...
type=CWD msg=audit(11/18/2026 14:22:09.314:412) : cwd=/home/operator
type=SYSCALL msg=audit(11/18/2026 14:22:09.314:412) : arch=x86_64 syscall=openat success=yes exit=3 ... auid=operator uid=root gid=root euid=root tty=pts1 comm=vi exe=/usr/bin/vi subj=unconfined key=sshd_cfg

Notice three critical details grouped under the shared event ID 412:

  • auid=operator shows the original authenticated user, even though uid=root and euid=root show the command ran via sudo.
  • comm=vi and exe=/usr/bin/vi reveal both the command name and the exact binary path executed.
  • PATH and CWD show which file was touched and from which working directory.

#Common mistakes

  • Forgetting ReadWritePaths= with ProtectSystem=strict: the service fails on startup when trying to write state or PID files. Check journalctl -u <unit> immediately after restarting.
  • Confusing uid with auid: if an attacker escalates via sudo or a misconfigured SUID binary, uid/euid becomes root, while auid stays anchored to the login account (or unset for unauthenticated daemons).
  • Running auditctl without saving to /etc/audit/rules.d/: rules added only with auditctl vanish on reboot unless persisted and loaded via augenrules --load.
  • Logging every execve without filters: broad syscall rules without euid=0 or directory scope can fill /var/log/audit and trigger disk-full audit actions.

#Summary

  • Inspect process ownership, ppid, and listening sockets (ps, ss) before changing service privileges.
  • Measure unit exposure with systemd-analyze security and apply drop-in overrides (NoNewPrivileges, ProtectSystem=strict, ProtectHome, PrivateTmp, CapabilityBoundingSet) via systemctl edit.
  • Deploy auditctl file-watch (-w) and syscall (-a) rules with -k keys, and persist them under /etc/audit/rules.d/.
  • Use ausearch -k <key> -i to link SYSCALL, PATH, and PROCTITLE records and rely on auid to identify the originating login session.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge