« Back to Settings for systemd units

ProtectSystem setting

The property ProtectSystem is a systemd unit setting used for sandboxing. It is available since systemd 214.

Purpose: mark some file system paths as read-only

Why and when to use ProtectSystem

The setting ProtectSystem reduces write access to specific paths based on the setting.

Generic advice

For most services ProtectSystem can be used with yes, full, or strict. The latter is the most strict setting and often requires ReadWritePaths to allow application-specific paths to work.

Testing

Use the systemd-run command to see if file creation is restricted by setting it to ‘strict’.

systemd-run --pty --property=ProtectSystem=strict touch ./testfile

This should return an error:

/usr/bin/touch: cannot touch './testfile': Read-only file system

Example configuration

Values

Define the paths that are granted write access.

[Service]
ProtectSystem=strict
ReadWritePaths=/var/log/application-logs /var/run/application

Caveats of ProtectSystem

The option ProtectSystem has no effect when:

  • kernel has no file system namespacing
  • service manager within a container manager that makes file system namespacing unavailable

Values

Systemd unit setting ProtectSystem expects a boolean (yes/no or true/false) or string value.

Values for systemd unit setting ProtectSystem
ValueIntended actionAvailable since
systemd version
nodo not limit file system for invoked processes - default
yesmount /usr and boot loader paths (/boot, /efi) read-only for invoked processes
fullmount /usr, /boot, /efi, /etc as read-only for invoked processes
strictmount full file system read-only, except /dev, /proc, and /sys

Example to show the current value of ProtectSystem for the ssh service:

systemctl show --property=ProtectSystem ssh.service

Related hardening profiles

The systemd unit setting ProtectSystem is used in the following hardening profiles.

Frequently Asked Questions

How to use systemctl edit?

Run systemctl with the 'edit' subcommand and service.

systemctl edit UNIT.service

See full answer at How to use systemctl edit to change a service?

Related articles

Like to learn more? Here is a list of articles within the same category or having similar tags.

Feedback

Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

Mastodon icon