SETPRIV(1)

๐Ÿ’– SETPRIV(1) ๐Ÿ’–

okay bestie, welcome to setpriv, a User Commands girlie from the util-linux family โœจ she's the one who runs a program with different Linux privilege settings, and she does it with zero drama and zero password prompts ๐Ÿ’…


๐ŸŒธ NAME ๐ŸŒธ

setpriv โ€” run a program with different Linux privilege settings ๐Ÿฆ‹


โœจ SYNOPSIS โœจ

setpriv [options] program [arguments]

๐Ÿ’œ DESCRIPTION ๐Ÿ’œ

So what she does is: she sets or queries various Linux privilege settings that get inherited across execve(2) ๐Ÿ‘‘

Now, compared to su(1) and runuser(1), our girl setpriv neither uses PAM nor prompts for a password. Not once. Not ever. She is a simple, non-set-user-ID wrapper around execve(2), and you can use her to drop privileges in exactly the same way as setuidgid(8) from daemontools, chpst(8) from runit, or whatever similar tools those other service managers ship ๐ŸŽ€


๐ŸŽ€ OPTIONS ๐ŸŽ€

  • --clear-groups โ€” Clear supplementary groups. bye bestie ๐Ÿ‘‹
  • -d, --dump โ€” Dump the current privilege state. You can specify this option more than once to show extra, mostly useless, information. Incompatible with all other options ๐Ÿšซ (yes, she said what she said)
  • --groups group... โ€” Set supplementary groups. The argument is a comma-separated list of GIDs or names.
  • --inh-caps (+|-)cap..., --ambient-caps (+|-)cap..., --bounding-set (+|-)cap... โ€” Set the inheritable capabilities, ambient capabilities or the capability bounding set. See capabilities(7). The argument is a comma-separated list of +cap and -cap entries, which add or remove an entry respectively. cap can either be a human-readable name as seen in capabilities(7) without the cap_ prefix or of the format cap_N, where N is the internal capability index used by Linux. +all and -all can be used to add or remove all caps ๐Ÿ”ฅ

The set of capabilities starts out as the current inheritable set for --inh-caps, the current ambient set for --ambient-caps and the current bounding set for --bounding-set.

Note the following restrictions (detailed in capabilities(7)) regarding modifications to these capability sets:

  • A capability can be added to the inheritable set only if it is currently present in the bounding set.
  • A capability can be added to the ambient set only if it is currently present in both the permitted and inheritable sets.
  • Notwithstanding the syntax offered by setpriv, the kernel does not permit capabilities to be added to the bounding set.
If you drop a capability from the bounding set without also dropping it from the inheritable set, you are likely to become confused. Do not do that. fr fr, do NOT do that ๐Ÿ˜ญ
  • --keep-groups โ€” Preserve supplementary groups. Only useful in conjunction with --rgid, --egid, or --regid.
  • --init-groups โ€” Initialize supplementary groups using initgroups3. Only useful in conjunction with --ruid or --reuid.
  • --list-caps โ€” List all known capabilities. This option must be specified alone, she's a solo act ๐Ÿ’…
  • --nnp, --no-new-privs โ€” Set the no_new_privs bit. With this bit set, execve(2) will not grant new privileges. For example, the set-user-ID and set-group-ID bits as well as file capabilities will be disabled. (Executing binaries with these bits set will still work, but they will not gain privileges. Certain LSMs, especially AppArmor, may result in failures to execute certain programs.) This bit is inherited by child processes and cannot be unset. See prctl(2) and Documentation/prctl/no_new_privs.txt in the Linux kernel source.

The no_new_privs bit is supported since Linux 3.5.

  • --rgid gid, --egid gid, --regid gid โ€” Set the real, effective, or both GIDs. The gid argument can be given as a textual group name.

For safety, you must specify one of --clear-groups, --groups, --keep-groups, or --init-groups if you set any primary gid ๐Ÿซถ

  • --ruid uid, --euid uid, --reuid uid โ€” Set the real, effective, or both UIDs. The uid argument can be given as a textual login name.

Setting a uid or gid does not change capabilities, although the exec call at the end might change capabilities. This means that, if you are root, you probably want to do something like:

setpriv --reuid=1000 --regid=1000 --inh-caps=-all
  • --securebits (+|-)securebit... โ€” Set or clear securebits. The argument is a comma-separated list. The valid securebits are noroot, noroot_locked, no_setuid_fixup, no_setuid_fixup_locked, and keep_caps_locked. keep_caps is cleared by execve(2) and is therefore not allowed ๐Ÿ™ˆ
  • --pdeathsig keep|clear|<signal> โ€” Keep, clear or set the parent death signal. Some LSMs, most notably SELinux and AppArmor, clear the signal when the process' credentials change. Using --pdeathsig keep will restore the parent death signal after changing credentials to remedy that situation.
  • --ptracer pid|any|none โ€” When Yama's restricted ptrace mode is in effect (that is, when /proc/sys/kernel/yama/ptrace_scope is set to 1), allow being traced via ptrace(2) by the process with the specified PID, or any process, or no process. See PR_SET_PTRACER(2const). (Note that this is not inherited by child processes, though it is preserved across execve(2).) This option has no effect when Yama is not enabled or is in a mode other than restricted ptrace.
  • --selinux-label label โ€” Request a particular SELinux transition (using a transition on exec, not dyntrans). This will fail and cause setpriv to abort if SELinux is not in use, and the transition may be ignored or cause execve(2) to fail at SELinux's whim. (In particular, this is unlikely to work in conjunction with no_new_privs.) This is similar to runcon(1).
  • --apparmor-profile profile โ€” Request a particular AppArmor profile (using a transition on exec). This will fail and cause setpriv to abort if AppArmor is not in use, and the transition may be ignored or cause execve(2) to fail at AppArmor's whim ๐Ÿ’€
  • --landlock-access access โ€” Enable landlock restrictions for a specific set of system accesses. To allow specific subgroups of accesses use --landlock-rule.

Block all filesystem access:

setpriv --landlock-access fs

Block all file deletions and directory creations:

setpriv --landlock-access fs:remove-file,make-dir

For a complete set of supported access categories use setpriv --help.

The generic placeholder "fs" is subject to change and may be extended in future versions to support new access types โญ

  • --landlock-rule rule โ€” Allow one specific access from the categories blocked by --landlock-access.

The syntax is as follows:

--landlock-rule $ruletype:$access:$rulearg

For example grant file read access to everything under /boot:

--landlock-rule path-beneath:read-file:/boot
  • --seccomp-filter file โ€” Load raw BPF seccomp filter code from a file.

Filters can for example be created with enosys ๐ŸŒˆ

  • --reset-env
    • clears all the environment variables except TERM environment variable
    • initializes the environment variables HOME, SHELL, USER, LOGNAME according to the user's passwd entry
    • the environment variable SHELL defaults to /bin/sh if none is given in the user's passwd entry.
    • resets PATH environment variable according to setting in /etc/login.defs (ENV_PATH, ENV_SUPATH or ENV_ROOTPATH variables), or defaults to /usr/local/bin:/bin:/usr/bin for a regular user and to /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin for root.

The environment variable PATH may be different on systems where /bin and /sbin are merged into /usr.

  • -h, --help โ€” Display help text and exit. ๐Ÿซถ
  • -V, --version โ€” Display version and exit. ๐Ÿ’–

๐Ÿ’… NOTES ๐Ÿ’…

If applying any specified option fails, program will not be run and setpriv will return with exit status 127 ๐Ÿ˜ญ

Be careful with this tool โ€” it may have unexpected security consequences. For example, setting no_new_privs and then execing a program that is SELinux-confined (as this tool would do) may prevent the SELinux restrictions from taking effect. no cap, be careful bestie โš ๏ธ

๐Ÿฆ‹ EXAMPLES ๐Ÿฆ‹

Note that setpriv is not a 1:1 replacement for su(1), runuser(1), or sudo(8). Unlike those tools, setpriv does not use PAM, does not prompt for a password, and does not perform session or accounting setup. The examples below provide a starting point for common privilege-dropping scenarios โœจ

If you want to switch UIDs/GIDs similarly to runuser(1) (without --login), try:

setpriv --reuid=1000 --regid=1000 --inh-caps=-all --init-groups

To also reset the environment (as sudo(8) does by default), add --reset-env:

setpriv --reuid=1000 --regid=1000 --inh-caps=-all --init-groups
--reset-env

For a more restrictive setup that also limits the bounding set and prevents gaining new privileges (more restrictive than runuser or sudo):

setpriv --reuid=1000 --regid=1000 --init-groups --inh-caps=-all
--bounding-set=-all --no-new-privs --reset-env

If you want to mimic daemontools' setuid(8), try:

setpriv --reuid=1000 --regid=1000 --clear-groups

๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

Andy Lutomirski <luto@amacapital.net> โ€” icon behavior honestly ๐Ÿ’œ


๐ŸŒˆ SEE ALSO ๐ŸŒˆ

runuser(1), su(1), prctl(2), capabilities(7), landlock(7) โ€” go read these too, iykyk ๐Ÿ“š


๐Ÿ“ REPORTING BUGS ๐Ÿ“

For bug reports, use the issue tracker <https://github.com/util-linux/util-linux/issues>. tell her everything, she can take it ๐Ÿ™ˆ


๐Ÿงš AVAILABILITY ๐Ÿงš

The setpriv command is part of the util-linux package which can be downloaded from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils/util-linux/> โญ


and that's the whole page bestie!! this one's util-linux 2.42.4, dated 2026-09-21, and it's literally SETPRIV(1) โ€” main character energy, periodt ๐Ÿ’…๐ŸŽ€๐Ÿ’–

๐Ÿ“ฆ where this page comes from
  • arch rolling: util-linux 2.42.4-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause-UC AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND ISC AND LGPL-2.1-or-later AND LicenseRef-PublicDomain
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms