table of contents
SETPRIV(1) | User Commands | SETPRIV(1) |
NAME¶
setpriv - run a program with different Linux privilege settings
SYNOPSIS¶
setpriv [options] program [arguments]
DESCRIPTION¶
Sets or queries various Linux privilege settings that are inherited across execve(2).
In comparison to su(1) and runuser(1), setpriv neither uses PAM, nor does it prompt for a password. It is a simple, non-set-user-ID wrapper around execve(2), and can be used to drop privileges in the same way as setuidgid(8) from daemontools, chpst(8) from runit, or similar tools shipped by other service managers.
OPTIONS¶
--clear-groups
-d, --dump
--groups group...
--inh-caps (+|-)cap..., --ambient-caps (+|-)cap..., --bounding-set (+|-)cap...
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:
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.
--keep-groups
--init-groups
--list-caps
--no-new-privs
The no_new_privs bit is supported since Linux 3.5.
--rgid gid, --egid gid, --regid gid
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
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...
--pdeathsig keep|clear|<signal>
--selinux-label label
--apparmor-profile profile
--landlock-access access
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.
--landlock-rule rule
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
--reset-env
The environment variable PATH may be different on systems where /bin and /sbin are merged into /usr. The environment variable SHELL defaults to /bin/sh if none is given in the user’s passwd entry.
-h, --help
-V, --version
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.
EXAMPLES¶
If you’re looking for behavior similar to su(1)/runuser(1), or sudo(8) (without the -g option), try something like:
setpriv --reuid=1000 --regid=1000 --init-groups
If you want to mimic daemontools' setuid(8), try:
setpriv --reuid=1000 --regid=1000 --clear-groups
AUTHORS¶
Andy Lutomirski <luto@amacapital.net>
SEE ALSO¶
REPORTING BUGS¶
For bug reports, use the issue tracker at <https://github.com/util-linux/util-linux/issues>.
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/>.
2024-07-04 | util-linux 2.40.2 |