brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ProtectHome=yes keeps a systemd service out of every home folder, a security one-liner

Security
~/tips/tip-security-systemd-protecthome

sudo systemctl edit myapp.service

Makes /home, /root and /run/user empty and unreachable for one service.

A web app or a download client has no business in /home. One line in its unit file makes sure it can’t look there even if it gets compromised.

Add it with a drop-in, so package updates don’t overwrite your change:

sudo systemctl edit myapp.service
[Service]
ProtectHome=yes

Then sudo systemctl restart myapp. For that service, /home, /root and /run/user are now empty and inaccessible. The rest of the system sees nothing different.

There are two softer values. read-only keeps the folders visible but stops writes, and tmpfs mounts an empty read-only file system over them. I’d start with yes and only step down when the service really needs something in a home folder.

To check what the service sees, run a quick command in the same sandbox:

sudo systemd-run -p ProtectHome=yes --wait --pipe ls /home

That should list nothing. The catch is services that keep their data in a home folder, such as an app running as a user whose files live under /home/app. With yes they fail to start or can’t find their data. Move the data to /var/lib/app, or use BindPaths= to let in the one folder the service needs.

Further reading: systemd.exec(5): ProtectHome=

More Security tips tcpdump -nn -r capture.pcap port 53 mkcert -install Strict-Transport-Security: max-age=0 Referrer-Policy: strict-origin-when-cross-origin wp super-admin list All Security tips (79) All topics

Link