Skip to content
Back to skills

Systemd Dynamic User

ASecurity

Run systemd services with `DynamicUser` unless there is a concrete reason to give them a fixed user, and create static users with fixed UIDs and GIDs only when such a reason exists. Use when defining or modifying systemd services in NixOS, or when about to add a system user for a service.

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
ai-agentssqlapi

Works with

  • api

Security analysis

A100/100

Scanned December 3, 2026

npx -y skills add ncaq/konoka --skill systemd-dynamic-user --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Systemd Dynamic User?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Systemd Dynamic User
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ncaq-systemd-dynamic-user/badge)](https://www.skillsdirectory.com/skills/ncaq-systemd-dynamic-user)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: systemd-dynamic-user
description: Run systemd services with `DynamicUser` unless there is a concrete reason to give them a fixed user, and create static users with fixed UIDs and GIDs only when such a reason exists. Use when defining or modifying systemd services in NixOS, or when about to add a system user for a service.
user-invocable: false
---

# systemdのサービスは`DynamicUser`で動かす

systemdのサービスは、動作に問題が無ければ`DynamicUser`で動かしてください。
固定のUIDとGIDを持つユーザは、固定が要る理由がある時だけ作ります。

```nix
{
  systemd.services.example.serviceConfig = {
    DynamicUser = true;
    StateDirectory = "example";
  };
}
```

`DynamicUser`のユーザは、ユニットの起動時に割り当てられ、停止すると解放されます。
UIDの割り当てとユーザの宣言を管理せずに済みます。
`ProtectSystem=strict`や`PrivateTmp`なども暗に有効になり、
サービスが書き込める場所が絞られます。

書き込みが要るディレクトリは、
`StateDirectory`、`CacheDirectory`、`LogsDirectory`、`RuntimeDirectory`で用意します。
systemdが動的なユーザの所有にして管理します。

nixpkgsのモジュールには、既定で`DynamicUser`を使うものが多くあります。
理由無く`DynamicUser = lib.mkForce false`で固定のユーザに変えないでください。

## 固定のユーザが要る場合

固定のユーザを足す前に、固定が要る理由があるかを確かめます。
例えば以下の場合です。

- 別のコンテナやホストにいる相手が、UIDをユーザ名に解決して認証する。
  PostgreSQLのpeer認証が当たります。
- ホストとコンテナのように境界をまたいで、
  他のサービスと同じデータ領域を同じユーザで読み書きする。
- 大きな永続データを持ち、UIDが変わるとsystemdがデータ全体の所有者を再帰的に書き換えることになる。
  ephemeralなコンテナでは起動のたびに全データをchownすることになりかねません。

APIを叩くだけのサービスのように理由が無いものは、`DynamicUser`で動かします。
固定のユーザにした場合は、その理由をコメントに書いてください。

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.