# Hardening systemd services

**URL:** https://discourse.nixos.org/t/hardening-systemd-services/17147
**Category:** Security
**Created:** [January 15, 2022, 7:02pm UTC](https://discourse.nixos.org/t/hardening-systemd-services/17147 "2022-01-15T19:02:32Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![Solene](https://discourse.nixos.org/user_avatar/discourse.nixos.org/solene/32/5738_2.png) [@Solene](https://discourse.nixos.org/u/Solene)
#### Post date: [January 16, 2022, 2:44pm UTC](https://discourse.nixos.org/t/hardening-systemd-services/17147/6 "2022-01-16T14:44:31Z")

</div>

This would be fine but depending on the service itself the hardening strategy will be different. That’s why I think using set of “profiles” that will define some knobs would be useful.

As someone maintaining a systemd unit, you would have to ask some questions:

- does it run as root? no, use profile run-as-user that will turn on: NoNewPrivileges / ProtectKernelLogs / ProtectKernelModules / ProtectKernelTunables / ProtectProc / RestrictSUIDSGID …
- does it do network? no, use profile no-network that will turn on: PrivateNetwork
- does it need to read all FS files? no? then enable PrivateUsers / PrivateTmp / ProtectSystem / ProtectProc …

then, define `harden = [run-as-user no-network no-fs];`

---

_[View the full topic](https://discourse.nixos.org/t/hardening-systemd-services/17147)._
