agentleFS
leroyguillaumeleroyguillaume/claude/system-user-conventions/SKILL.md

system-user-conventions

Skill7 starsChanged 3 days agoMITView on GitHub

Unix service accounts, groups, ownership and modes. TRIGGER when: creating or reviewing an account or group (`useradd`, `groupadd`, `sysusers.d`, cloud-init `users:`, Ansible `user`, `Dockerfile` `USER`); granting sudo or a group; setting ownership or modes on service files; SSH access or a deploy/CI account; user asks who a process runs as. SKIP when: no account, group, ownership or login is involved.

  • Reads credentials
  • Deletes or force-pushes

1 other project uses a version of this.

Adopted by

Most recently taken up by

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
  1. Very specific:

    One account per service, named after the app: Never a shared catch-all (www-data running three apps means a bug in one reads the secrets of …

    line 27
  2. Very specific:

    Never an interactive adduser in a runbook: it prompts, so it cannot be automated, and it silently defaults to a real shell and a /home …

    line 111
  3. Very specific:

    chown -R myapp /opt/myapp is not a fix: When a permission error shows up, find the single path that must be writable and grant that one — …

    line 131

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

System user conventions

A service account exists so that a compromised process is stuck being that process: it cannot log in, cannot be logged into, cannot become anything else, and owns nothing it does not strictly need. Every property below removes one way out of that box — which is why "it was easier with a shell" is never a reason.

The unit-file side of this (User=, DynamicUser=, the sandboxing block) lives in systemd-conventions; the container side (UID/GID 65532, distroless nonroot) in docker-conventions. This skill is the account itself, wherever it is created.

The account

  • One account per service, named after the app. Never a shared catch-all (www-data running three apps means a bug in one reads the secrets of the other two), and never a human's account.
  • Never nobody / nogroup (65534). It is shared by every unmapped process on the box and is what NFS squashes root to, so "owned by nobody" effectively means "owned by everybody". Same reasoning as avoiding it in containers.
  • --system: a UID from the system range (100–999 on Debian/RHEL), no password aging, no expiry, not counted as a login account. In a container image the number is different on purpose — UID/GID 65532, see docker-conventions — because a container UID is a host UID.
  • Shell /usr/sbin/nologin (/sbin/nologin on RHEL and Alpine). It refuses the session and exits non-zero, which kills interactive SSH, su -, and ssh host command — everything goes through the login shell. Prefer it to /bin/false, which does the same thing silently and leaves the user wondering. Never /bin/bash "for debugging": to get a shell as the service account, use sudo -u myapp on a specific command, runuser -u myapp -- …, or systemd-run --uid=myapp --pty …. None of those need the account to have a shell of its own.
  • Password locked, never a hash, and never an empty field — an empty second field in /etc/shadow is a passwordless account, which some PAM stacks happily accept. passwd --lock / lock_passwd: true / password: '!' all write the ! that means "locked". Caveat worth knowing: locking the password does not block SSH key auth. nologin plus an empty ~/.ssh/authorized_keys is what closes that door.
  • Home is the state directory, or nothing. Point it at the state directory the service already has (/var/lib/myapp, created by systemd's StateDirectory=, not by useradd -m); with no state directory, home is /nonexistent and none is created. Never /home — it is for humans, is frequently a separate or NFS-mounted filesystem, and useradd -m copies /etc/skel dotfiles nobody will ever read. Never /etc/myapp — config is root-owned, and a home there is how it ends up chowned to the service.
  • No sudo, no wheel, no adm. And specifically no docker group: a member can run docker run -v /:/host, which is root with extra steps. lxd and libvirt are the same trap. Adding a service account to any of them undoes every other line on this page.
  • Supplementary groups only for a resource the service must actually reach, one group per shared resource (myapp in certs to read a TLS key). Not "because it was the quickest way to fix a permission error".

Create it declaratively

Provisioning that runs useradd imperatively has to answer "what if it already exists?" — useradd exits 9 when it does, so the script fails on the second run. Every form below is idempotent by construction:

  • systemd-sysusers is the default on a systemd host or in an image — /usr/lib/sysusers.d/myapp.conf when a package or image ships it, /etc/sysusers.d/myapp.conf on a hand-provisioned host; applied at package install and at boot:

    #Type Name  ID  GECOS            Home dir      Shell
    u     myapp -   "myapp service"  /var/lib/myapp /usr/sbin/nologin
  • cloud-init, when the account comes up with the machine. Keep - default first: a users: list without it skips the distro's default user, and top-level ssh_authorized_keys then lands on no account:

    users:
      - default
      - name: myapp
        system: true
        shell: /usr/sbin/nologin
        lock_passwd: true
        homedir: /var/lib/myapp
        no_create_home: true
  • Ansible: ansible.builtin.user with system: true, shell: /usr/sbin/nologin, home: /var/lib/myapp, create_home: false, password: '!'.
  • Dockerfile: useradd --system --uid 65532 --gid myapp --shell /usr/sbin/nologin --home /nonexistent --no-create-home myapp (full form and rationale in docker-conventions).
  • A shell script, only when nothing above fits — and then guarded:

    id -u myapp >/dev/null 2>&1 || useradd --system \
        --shell /usr/sbin/nologin --home-dir /var/lib/myapp --no-create-home myapp

Never an interactive adduser in a runbook: it prompts, so it cannot be automated, and it silently defaults to a real shell and a /home directory.

What the account owns

The account's privileges are not only in /etc/passwd — they are in the file modes around it.

ThingOwnerModeWhy
Binary, /usr/local/bin/myapproot:root0755A service that can write its own binary rewrites it after a compromise and survives every restart
Unit file, timers, /etc/systemd/**root:root0644Writing them is a direct path back to root
Config directory, /etc/myapp/root:root0755 (what ConfigurationDirectory= creates)Holds nothing secret itself; the files' modes guard their content
Config files, /etc/myapp/*root:myapp0640Readable by the service, writable by nobody but root
Secret fileroot:root, or root:myapp when the service opens it itself0600, or 0640LoadCredential= and EnvironmentFile= are read by PID 1 — see systemd-conventions
State, /var/lib/myapp/myapp:myapp0700 (StateDirectoryMode=0700; the default is 0755)The one place it writes
Runtime, /run/myapp/myapp:myapp0700 (RuntimeDirectoryMode=0700)Sockets and PIDs; wiped on stop, so nothing stale survives a restart
Cache, /var/cache/myapp/myapp:myapp0700 (CacheDirectoryMode=0700)Disposable, but its content is still the service's own
Logs, /var/log/myapp/myapp:myapp0700 (LogsDirectoryMode=0700)Own log files; the rest of the box has no need to read them
  • chown -R myapp /opt/myapp is not a fix. When a permission error shows up, find the single path that must be writable and grant that one — usually it turns out to be a StateDirectory= that was missing.
  • chmod 777 is never the answer, in any script, ever. If two accounts must share a directory, that is a group plus 2770 (setgid so new files inherit the group), not world-writable.
  • UMask=0077 in the unit's hardening block (systemd-conventions), so whatever the app creates at runtime is not readable by the rest of the box by default.

Humans are the mirror image

  • One account per person, never a shared admin / deploy / ops login. A shared account has no audit trail: sudo logs "admin ran rm -rf", and the machine has no idea which of the six people that was.
  • Real shell, key-based SSH only (PasswordAuthentication no, PermitRootLogin no), sudo through a group (wheel / sudo), not a per-user sudoers line. NOPASSWD only where the workflow genuinely cannot prompt, and scoped to the commands that need it.
  • A CI or deploy account that must accept SSH is the one exception to nologin — it needs a shell to run the command. Constrain it instead: a forced command and lockdown options in authorized_keys (restrict,command="/usr/local/bin/deploy"), no sudo, no interactive session, and its own key per pipeline so a single key can be revoked.
  • Removing someone is removing the account, not just their key — and their group memberships go with it.

Audit what is actually on the box

Cheap checks worth running when you inherit a machine or finish provisioning one:

# accounts that can actually log in
awk -F: '$7 !~ /(nologin|false)$/ {print $1, $3, $7}' /etc/passwd

# unlocked passwords: hash not starting with ! or * (run as root)
awk -F: '$2 !~ /^[!*]/ {print $1}' /etc/shadow

# empty password field — passwordless login on a permissive PAM stack
awk -F: '$2 == "" {print $1}' /etc/shadow

# who holds root-equivalent group membership
getent group sudo wheel adm docker lxd libvirt

And the one that matters most after a deploy: systemctl show myapp.service -p User -p Group — the account the service actually runs as, rather than the one the config says it should.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.