SYSUSERS.D(5)

πŸ“¦
version 0.7.3 Β· 2 versions
  • 0.7.3 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu questing, ubuntu resolute (latest)
  • 0.6 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing, ubuntu resolute

πŸ‘‘ SYSUSERS.D πŸ‘‘ (that's sysusers.d(5) bestie, section 5, we're in the deep lore now)

okay so. this is THE page. the one where your system gets its little guys β€” its system users and system groups β€” declared up front instead of you manually poking at /etc/passwd like a gremlin. no cap. let's go. πŸ’…


✨ NAME ✨

sysusers.d β€” Declarative allocation of system users and groups

(yes "declarative" β€” you say what you want and the machine does it. main character energy fr fr 🌸)


✨ SYNOPSIS ✨

/etc/sysusers.d/*.conf

/run/sysusers.d/*.conf

/usr/lib/sysusers.d/*.conf

#Type Name       ID                  GECOS              Home directory Shell
u     user_name  uid                 "User Description" /home/dir      /path/to/shell
u     user_name  uid:gid             "User Description" /home/dir      /path/to/shell
u     user_name  /file/owned/by/user "User Description" /home/dir      /path/to/shell
g     group_name gid
g     group_name /file/owned/by/group
m     user_name  group_name
r     -          lowest-highest

like look at that table. five little columns. five little vibes. we'll get to each one I PROMISE. πŸŽ€


✨ DESCRIPTION ✨

so systemd-sysusers reads the files sitting in the sysusers.d directory and uses them to create system users and groups and to add users to groups β€” either when a package gets installed, or at boot time. that's the whole job. πŸ’–

heads up bestie: this tool is for allocating system users and groups only. it is not useful for creating non-system (i.e. regular, "human") users and groups. why? because it goes straight at /etc/passwd and /etc/group directly, bypassing any more complex user databases β€” so anything involving NIS or LDAP is simply not invited to this party. πŸ™ˆ

✨ CONFIGURATION DIRECTORIES AND PRECEDENCE ✨

every config file has to be named like package.conf or package-part.conf. that second flavour? use it when you want it to be easy to override just this one part of the config. sliceable config. obsessed. ✨

the override chain, in order of who wins:

  • files in /etc/sysusers.d override files with the same name in /usr/lib/sysusers.d and /run/sysusers.d
  • files in /run/sysusers.d override files with the same name in /usr/lib/sysusers.d

packages should install their config files in /usr/lib/sysusers.d. and /etc/sysusers.d is reserved for the local administrator β€” that's you, the local admin, the boss β€” who may use this logic to override the config files installed by vendor packages. πŸ‘‘

all config files get sorted by their filename in lexicographic order, no matter which of the directories they live in. if multiple files specify the same path, the entry in the file with the lexicographically earliest name wins. and every later entry for the same user and group names? those get logged as warnings. so like, you'll know. 😭

want to disable a config file that a vendor shipped you? the recommended way is to drop a symlink to /dev/null in /etc/sysusers.d/ bearing the same filename. iconic. instant veto. πŸ’…


✨ CONFIGURATION FILE FORMAT ✨

the format is one line per user or group, containing name, ID, GECOS field description, home directory, and login shell:

#Type Name     ID             GECOS                 Home directory Shell
u     httpd    404            "HTTP User"
u     _authd   /usr/bin/authd "Authorization user"
u     postgres -              "Postgresql Database" /var/lib/pgsql /usr/libexec/postgresdb
g     input    -              -
m     _authd   input
u     root     0              "Superuser"           /root          /bin/zsh
r     -        500-900

empty lines and lines beginning with the "#" character are ignored, and may be used for commenting. comment away, it's your file. πŸ¦‹

✨ Type ✨

the type is a single letter. here's the whole alphabet of what's understood:

  • u β€” Create a system user and group of the specified name should they not exist yet. The user's primary group will be set to the group bearing the same name unless the ID field specifies it. The account will be created disabled, so that logins are not allowed.
  • g β€” Create a system group of the specified name should it not exist yet. Note that u implicitly creates a matching group. The group will be created with no password set.
  • m β€” Add a user to a group. If the user or group do not exist yet, they will be implicitly created.
  • r β€” Add a range of numeric UIDs/GIDs to the pool to allocate new UIDs and GIDs from. If no line of this type is specified, the range of UIDs/GIDs is set to some compiled-in default. Note that both UIDs and GIDs are allocated from the same pool, in order to ensure that users and groups of the same name are likely to carry the same numeric UID and GID.

✨ Name ✨

the name field is the user or group name. the rules are strict and they are not playing:

  • the name must consist only of the characters a-z, A-Z, 0-9, "_" and "-"
  • except the first character, which must be one of a-z, A-Z or "_" β€” so numbers and "-" are not permitted as the first character
  • the user/group name must have at least one character, and at most 31

for further details about the syntax of user/group names, see User/Group Name Syntax[1].

it is strongly recommended to pick user and group names that are unlikely to clash with normal users created by the administrator. a good scheme to guarantee this is by prefixing all system and group names with the underscore, and avoiding too generic names. (do it. future you will thank you. 🫢)

for m lines, this field should contain the user name to add to a group.

for lines of type r, this field should be set to "-".

✨ ID ✨

for u and g: the numeric 32-bit UID or GID of the user/group.

do NOT use IDs 65535 or 4294967295 β€” they have special placeholder meanings. πŸ’€

specify "-" for automatic UID/GID allocation for the user or group. this is strongly recommended unless it is strictly necessary to use a specific UID or GID.

alternatively, specify an absolute path in the file system. in that case, the UID/GID is read from the path's owner/group. this is useful to create users whose UID/GID match the owners of pre-existing files (such as SUID or SGID binaries). πŸ”₯

the syntaxes "uid:gid" and "uid:groupname" are supported to allow creating users with specific primary groups. the given group must be created explicitly, or it must already exist. specifying "-" for the UID in these syntaxes is also supported.

for m lines, this field should contain the group name to add to a user to.

for lines of type r, this field should be set to a UID/GID range in the format "FROM-TO", where both values are formatted as decimal ASCII numbers. alternatively, a single UID/GID may be specified formatted as decimal ASCII numbers.

✨ GECOS ✨

a short, descriptive string for users to be created, enclosed in quotation marks.

note: this field may not contain colons. 🚫

only applies to lines of type u and should otherwise be left unset (or "-").

✨ Home Directory ✨

the home directory for a new system user. if omitted, it defaults to the root directory.

only applies to lines of type u and should otherwise be left unset (or "-"). it is recommended to omit this, unless software strictly requires a home directory to be set.

systemd-sysusers only sets the home directory record in the user database. to actually create the directory, consider adding a corresponding tmpfiles.d(5) fragment. (yes bestie, that's your next reading assignment. πŸ“š)

✨ Shell ✨

the login shell of the user. if not specified, this will be set to /usr/sbin/nologin β€” except if the UID of the user is 0, in which case /bin/sh will be used.

only applies to lines of type u and should otherwise be left unset (or "-"). it is recommended to omit this, unless a shell different /usr/sbin/nologin must be used.


okay that's the whole first chunk and I'm not even done with you yet β€” more parts incoming, don't go anywhere. 🧚

🌈 Table 1. Specifiers available

Okay bestie, this is the fun part. Specifiers are little magic shortcuts you can drop into the "Name", "ID", "GECOS", "Home directory", and "Shell" fields and they get expanded for you at read time. πŸ’…

Real talk though: if a specifier is unknown or can't be resolved, it's treated as invalid configuration. Not a warning, not a vibe β€” invalid. So don't freestyle these. 😭

Here's every single one, no skips, no shortcuts:

  • %a β€” Architecture</p> β€” a short string identifying the architecture of the local system. Something like x86, x86-64 or arm64. Wanna see the full list? Check the architectures defined for ConditionArchitecture= in systemd.unit(5). ✨
  • %A β€” Operating system image version</p> β€” the operating system image version identifier of the running system, read straight from the IMAGE_VERSION= field of /etc/os-release. If that field isn't set, it resolves to an empty string. More deets in os-release(5). πŸ¦‹
  • %b β€” Boot ID</p> β€” the boot ID of the running system, formatted as string. random(4) has the lore. 🌸
  • %B β€” Operating system build ID</p> β€” the operating system build identifier of the running system, as read from the BUILD_ID= field of /etc/os-release. Not set? Empty string, bestie. See os-release(5). πŸ’–
  • %H β€” Host name</p> β€” the hostname of the running system. That's it, that's the whole thing. πŸŽ€
  • %l β€” Short host name</p> β€” the hostname of the running system, truncated at the first dot to remove any domain component. So the whole domain part just βœ‚οΈ gone.
  • %m β€” Machine ID</p> β€” the machine ID of the running system, formatted as string. machine-id(5) if you want more. 🧚
  • %M β€” Operating system image identifier</p> β€” the operating system image identifier of the running system, as read from the IMAGE_ID= field of /etc/os-release. If not set, resolves to an empty string. See os-release(5). πŸ’œ
  • %o β€” Operating system ID</p> β€” the operating system identifier of the running system, as read from the ID= field of /etc/os-release. os-release(5) for more information. ⭐
  • %T β€” Directory for temporary files</p> β€” this is either /tmp or the path "$TMPDIR", "$TEMP" or "$TMP" are set to. (Note that the directory may be specified without a trailing slash.) 🌈
  • %v β€” Kernel release</p> β€” identical to uname -r output. Iconic, no notes. πŸ‘‘
  • %V β€” Directory for larger and persistent temporary files</p> β€” this is either /var/tmp or the path "$TMPDIR", "$TEMP" or "$TMP" are set to. (Note that the directory may be specified without a trailing slash.) πŸ”₯
  • %w β€” Operating system version ID</p> β€” the operating system version identifier of the running system, as read from the VERSION_ID= field of /etc/os-release. If not set, resolves to an empty string. See os-release(5). πŸ“
  • %W β€” Operating system variant ID</p> β€” the operating system variant identifier of the running system, as read from the VARIANT_ID= field of /etc/os-release. If not set, resolves to an empty string. See os-release(5). πŸ’«
  • %% β€” Single percent sign</p> β€” use "%%" in place of "%" to specify a single percent sign. Yes really, that's how you escape it. 🫢

Lowkey important: notice how %A, %B, %M, %w and %W all say "if not set, resolves to an empty string"? That's not a glitch, that's the documented behaviour, fr fr. And %o is the odd one out β€” it doesn't have that clause, so don't go assuming. 😭

Also clock that %T and %V both pull from the same "$TMPDIR", "$TEMP", "$TMP" trio β€” they're siblings, just one's for /tmp energy and one's for /var/tmp energy. πŸ’…

✨ IDEMPOTENCE ✨

okay bestie this is the part where you can just chill πŸ’…

note that systemd-sysusers will do absolutely nothing if the users or groups you're asking for already exist, or if the users are already members of the groups you listed. like, it looks at the situation, goes "been there, done that 🫢", and moves on.

which means: normally there is no reason to override vendor config in sysusers.d at all. no cap. the only reason you'd ever wanna do it is to block certain users or groups from being created in the first place β€” that's it, that's the whole use case.


🌈 SEE ALSO

go read those, they're giving main character energy fr fr πŸ‘‘


πŸ“ NOTES

  1. User/Group Name Syntax β€” https://systemd.io/USER_NAMES

and that's a wrap on the whole page, babe ✨ you made it all the way to the end, iconic behavior honestly πŸŽ€

this little masterpiece is from systemd 238.51, and yeah it's the SYSUSERS.D(5) page β€” the date lives down there in the footer with the version, so consider this your cute sign-off 🌸 mwah, go create some users responsibly πŸ’–

πŸ“¦ where this page comes from