Create and Harden a Custom systemd Service
A supplied application needs to run as a service under its own account, with a controlled environment, an automatic restart, and a filesystem sandbox that lets it write to one place and nothing else.
Skill labintermediate~45 minPro
What you'll do
- ✓Create a system account and a state directory for a service
- ✓Write a unit with User, WorkingDirectory, ExecStart, EnvironmentFile and Restart
- ✓Add NoNewPrivileges, PrivateTmp, ProtectSystem=strict and ReadWritePaths without breaking the app
- ✓Verify with systemd-analyze, prove the sandbox from the service account, and watch it recover from a crash
Lab outline
- 01Identity
- 02The unit
- 03Harden
Before you start
- Delegate a Narrowly Scoped sudo Action
- Operate systemd Services
Every lab runs on a real machine of your own in the browser — no installs, nothing to clean up — and checks your work automatically as you go.