systemd-conventions
Skill7 starsChanged 3 days agoMITView on GitHub
systemd units and cloud-init, centred on service privileges. TRIGGER when: editing a `.service`, `.socket`, `.timer` or drop-in `override.conf`; writing `#cloud-config`/user-data (Terraform `user_data`, Packer, Ignition); making an app start at boot on a VM; user asks about systemd, service hardening, running as root or cloud-init. SKIP when: the workload runs in Kubernetes or Compose (`docker-conventions`, `helm-conventions`).
1 other project uses a version of this.
Adopted by
Most recently taken up by
- leroyguillaume/claudeword for word, first seen Nov 29, 2026
Other versions1 project uses a version of this.
Word for word · 1
- leroyguillaume/claude★ 7100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository54 other files it gives its agents.
- adr-conventionsSkill
- api-conventionsSkill
- architecture-conventionsSkill
- argocd-conventionsSkill
- ci-conventionsSkill
- config-conventionsSkill
- contributing-conventionsSkill
- councilSkill
- cryptography-conventionsSkill
- dependency-update-conventionsSkill
- diagram-conventionsSkill
- docker-conventionsSkill
- documentation-conventionsSkill
- frontend-conventionsSkill
- github-actions-conventionsSkill
- github-issue-conventionsSkill
- github-pr-conventionsSkill
- github-repo-settingsSkill
- gitlab-ci-conventionsSkill
- helm-conventionsSkill
- herdr-core-delegationSkill
- herdr-delegationSkill
- herdr-tui-delegationSkill
- kopf-conventionsSkill
- kubernetes-operator-conventionsSkill
- logging-conventionsSkill
- logo-conventionsSkill
- mise-conventionsSkill
- ollama-conventionsSkill
- openssf-conventionsSkill
- pr-conventionsSkill
- pre-commit-conventionsSkill
- project-metadata-conventionsSkill
- python-async-conventionsSkill
- python-conventionsSkill
- readme-conventionsSkill
- release-script-conventionsSkill
- release-supply-chain-conventionsSkill
- renovate-ci-conventionsSkill
- rest-conventionsSkill
- rust-build-conventionsSkill
- rust-conventionsSkill
- rust-http-conventionsSkill
- security-policy-conventionsSkill
- signal-handling-conventionsSkill
- sql-conventionsSkill
- starlight-conventionsSkill
- system-user-conventionsSkill
- task-conventionsSkill
- terraform-conventionsSkill
- topic-splittingSkill
- ui-copy-conventionsSkill
- web-layout-conventionsSkill
- yaml-conventionsSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 32
Create it declaratively (systemd-sysusers or cloud-init's users: block), never with a useradd buried in runcmd.
- Very specific: line 55
ExecStartPre=runs as the service user too: If a preparation step genuinely needs root, mark that one line + (ExecStartPre=+/usr/bin/…) … - Very specific: line 134
Every *DirectoryMode= defaults to 0755, and UMask= does not apply to these directories — without the explicit mode, the rest of the box can …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
systemd and cloud-init conventions
On a VM, the unit file is the security boundary — there is no pod security
context, no admission controller, nothing else between the process and the
machine. A service running as root because it was quicker to write is a root
shell one deserialisation bug away. Everything below is about closing that
gap, and it costs about fifteen lines of ini.
The service does not run as root
User=andGroup=in every unit, always. A dedicated system account per service, named after the app, with no login shell and no password:[Service] User=myapp Group=myappCreate it declaratively (
systemd-sysusersor cloud-init'susers:block), never with auseraddburied inruncmd. How, and the account's own properties — shell, password, home, groups, and the file modes around it — aresystem-user-conventions.DynamicUser=yeswhen the service only touches its own state. systemd allocates a transient UID for the lifetime of the unit, and impliesProtectSystem=strict,PrivateTmp=,RemoveIPC=and friends. Do not use it when the UID must be stable across reboots (NFS, a shared volume, files another account reads) — state then lives under/var/lib/private/with a UID that changes under you.Never
User=root, and never a wrapper that shells out tosudo. If root looks necessary, name the one capability that is actually needed and grant only that:CapabilityBoundingSet=CAP_NET_BIND_SERVICE AmbientCapabilities=CAP_NET_BIND_SERVICEFor a port below 1024 the better answer is usually to not need the capability: bind a high port and put the reverse proxy in front, or let a
.socketunit (owned by root, activated as the service user) hold the privileged listener.ExecStartPre=runs as the service user too. If a preparation step genuinely needs root, mark that one line+(ExecStartPre=+/usr/bin/…) rather than promoting the whole unit.PermissionsStartOnly=is deprecated — do not write it.
The hardening block
Paste this into every long-running unit, then remove only what demonstrably breaks the app — with a comment saying what broke:
[Service]
User=myapp
Group=myapp
NoNewPrivileges=true
CapabilityBoundingSet=
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
PrivateDevices=true
ProtectProc=invisible
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
ProtectControlGroups=true
ProtectClock=true
ProtectHostname=true
RestrictNamespaces=true
RestrictRealtime=true
RestrictSUIDSGID=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
LockPersonality=true
MemoryDenyWriteExecute=true
SystemCallArchitectures=native
SystemCallFilter=@system-service
UMask=0077
StateDirectory=myapp
StateDirectoryMode=0700What each of the load-bearing ones actually buys, since a directive nobody understands is a directive somebody deletes:
NoNewPrivileges=true— the process and every child can never gain privileges again, so a setuid binary reachable from the service (sudo,mount,pkexec) becomes inert. This is the single highest-value line; it is also what makesSystemCallFilter=enforceable.ProtectSystem=strict— the entire filesystem is read-only except/dev,/proc,/sys. Combined withProtectHome=true(/home,/root,/run/userempty), a compromised service cannot persist anything on disk.CapabilityBoundingSet=(empty) — drops every capability, including the ones a root-owned parent might have handed down. List capabilities explicitly when one is genuinely needed; never leave it unset.MemoryDenyWriteExecute=true— blocks W+X mappings. It breaks every JIT runtime: Node, the JVM, .NET, LuaJIT, anything with a tracing JIT. Drop it for those, keep it for Rust/Go/C binaries.SystemCallFilter=@system-service— a seccomp allowlist covering what a normal daemon does. Add narrow groups when needed (SystemCallFilter=~@privileged @resourcesstyle subtraction is fine), never replace it with nothing.
Writable paths are declared, not chmod-ed
ProtectSystem=strict means the app cannot write anywhere it has not been
given. Grant that with the *Directory= directives, never with a mkdir -p
plus chown in provisioning:
| Need | Directive | Path |
| Persistent state | StateDirectory=myapp + StateDirectoryMode=0700 | /var/lib/myapp |
| Runtime sockets/PIDs | RuntimeDirectory=myapp + RuntimeDirectoryMode=0700 | /run/myapp, wiped on stop |
| Caches | CacheDirectory=myapp + CacheDirectoryMode=0700 | /var/cache/myapp |
| Own log files | LogsDirectory=myapp + LogsDirectoryMode=0700 | /var/log/myapp |
| Config | ConfigurationDirectory=myapp + ConfigurationDirectoryMode=0755 | /etc/myapp |
Who owns each path, and the modes of the files inside, are
system-user-conventions.
Every *DirectoryMode= defaults to 0755, and UMask= does not apply to
these directories — without the explicit mode, the rest of the box can list
and read them. The config directory keeps 0755 on purpose: systemd creates
it root:root and never changes its owner, so a 0750 locks the service out.
systemd creates them with the right owner and mode before ExecStart=, and
recreates them if they are missing — provisioning that pre-creates them by
hand is one chown away from being wrong and never noticed. ReadWritePaths=
is the last resort, for a path the app does not own (a data mount, a socket
directory shared with another service); list the narrowest path that works.
Logging goes to stdout/stderr and the journal — no log file, no logrotate
config, no LogsDirectory= at all in the normal case. See
logging-conventions.
Secrets never sit in the unit file
- Never
Environment=API_TOKEN=…. Unit files are world-readable, andsystemctl show myapp.serviceprints the environment to any unprivileged user on the box. Same for a secret on theExecStart=command line: it is in/proc/<pid>/cmdline, visible inps. Prefer
LoadCredential=: the file is mounted read-only into the service's private credential directory, owned by the service user, invisible to every other process and never in the journal:LoadCredential=api-token:/etc/myapp/api-tokenThe app reads
$CREDENTIALS_DIRECTORY/api-token.SetCredential=inlines a value in the unit — that is the same leak asEnvironment=, so only for non-secret data.EnvironmentFile=/etc/myapp/envis the acceptable fallback for apps that only read the environment:root:root, mode0600— PID 1 reads it, not the service.
cloud-init
The provisioning file is where privileges are handed out for the life of the machine, and it is very easy to hand out too many.
runcmdandbootcmdrun as root with no sandbox —runcmdonce per instance,bootcmdon every boot. Use them to install and enable —systemctl enable --now myapp.service— never to run the application itself. An app started fromruncmdis a root process with no unit, no restart, no hardening and no journal identity.Every
write_filesentry carries explicitowner:andpermissions:. The defaults areroot:rootand0644; a credential written with the defaults is readable by every account on the machine. Quote the mode so YAML does not mangle the leading zero. An entry owned by the service account needsdefer: true, or it is written beforeusers:creates the account and thechownfails:write_files: - path: /etc/myapp/config.toml owner: root:myapp permissions: '0640' defer: true content: "" - path: /etc/systemd/system/myapp.service owner: root:root permissions: '0644' content: | [Unit] Description=myapp- The service account gets no sudo, ever —
system-user-conventionsowns that rule and has theusers:block. - Lock the box's own doors:
disable_root: true,ssh_pwauth: false, keys viassh_authorized_keysonly. No password hashes in user-data. - Never put a secret in user-data. It stays readable for the instance's
entire life from the metadata endpoint (
169.254.169.254) by any process on the machine, including the compromised one, and most providers keep it in the instance description too. Provision the value from the cloud's secret manager at boot, or place the file out of band and reference it withLoadCredential=. write_filesruns beforeruncmd— rely on that ordering rather than re-writing files fromruncmd. After dropping a unit file,runcmdneedssystemctl daemon-reloadbeforeenable --now.- Block style YAML only (
yaml-conventions), and validate the file:cloud-init schema --config-file cloud-config.yaml.
Verify, don't assume
systemd-analyze security myapp.serviceis the lint for a unit. Run it after every unit change. A bare unit with no hardening scores around 9.6 ("UNSAFE"); the block above typically lands between 1 and 3 ("OK"). Treat anything above 5.0 as unfinished work, and read the per-directive table it prints rather than guessing which line is missing. For a unit file in the repo that is not installed,systemd-analyze security --offline=true ./myapp.service(systemd ≥ 250).systemd-analyze verify ./myapp.servicecatches typos and bad references — an unknown directive is silently ignored at runtime, so a misspelledProtectSytem=fails open, quietly, forever.systemctl show myapp.service -p User -p CapabilityBoundingSet -p NoNewPrivilegesafter deploying: it prints what is effective, which is the only thing that counts. Andsystemctl statusshould show the service running under the expected UID.- Vendor units are never edited in place. Override with a drop-in:
/etc/systemd/system/myapp.service.d/override.conf, thensystemctl daemon-reload.
Also in the unit, while you are there
Restart=on-failurewithRestartSec=— and the process handlesSIGTERMso the restart is clean (signal-handling-conventions).Type=notifywhen the app can signal readiness,Type=execotherwise.Type=simpleclaims readiness before the process has done anything, soAfter=ordering on it means nothing.TimeoutStopSec=longer than the app's drain window, otherwise systemdSIGKILLs mid-drain — exactly the failure the drain logic exists to avoid.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

