sudo
executes a command as anonther user, called the target user, which typically is root. sudo -i
. -A | --askpass | use a helper program for password prompting |
-b | --background | run command in the background |
-B | --bell | ring bell when prompting |
-C | --close-from=num | close all file descriptors >= num |
-D | --chdir=directory | change the working directory before running command |
-E | --preserve-env | preserve user environment when running command |
--preserve-env=list | preserve specific environment variables | |
-e | --edit | edit files instead of running a command |
-g | --group=group | run command as the specified group name or ID |
-H | --set-home | set HOME variable to target user's home directory |
-h | --help | display help message and exit |
-h | --host=host | run command on host (if supported by plugin) |
-i | --login | run login shell as the target user; a command may also be specified |
-K | --remove-timestamp | remove timestamp file completely |
-k | --reset-timestamp | invalidate timestamp file |
-l | --list | list user's privileges or check a specific command; use twice for longer format |
-n | --non-interactive | non-interactive mode, no prompts are used |
-P | --preserve-groups | preserve group vector instead of setting to target's |
-p | --prompt=prompt | use the specified password prompt |
-R | --chroot=directory | change the root directory before running command |
-r | --role=role | create SELinux security context with specified role |
-S | --stdin | read password from standard input |
-s | --shell | run shell as the target user; a command may also be specified |
-t | --type=type | create SELinux security context with specified type |
-T | --command-timeout=timeout | terminate command after the specified time limit |
-U | --other-user=user | in list mode, display privileges for user |
-u | --user=user | run command (or edit file) as specified user name or ID |
-V | --version | display version information and exit |
-v | --validate | update user's timestamp without running a command |
-- | stop processing command line arguments |
-u
flag must be specified: sudo -u fred ls ~fred
sudo
, the following line can be added to the sudoers file: fred ALL=(ALL) NOPASSWD:ALL
#!/bin/sh echo SecretGarden
SUDO_ASKPASS
: export SUDO_ASKPASS=~/bin/password
-A
option, sudo will execute the shell script and take the password from this shell script: sudo -A do-something.sh
/etc/sudoers
are allowed to run sudo
. If a user that is not listed in this file tries to run sudo
, sudo
will print the error message USERNAME is not in the sudoers file. This incident will be reported. /etc/sudoers
specifies specific groups whose members are allowed to execute sudo
, for example a group named sudo or wheel. # usermod -aG sudo rene
$ newgrp sudo
/tmp/xyz
. Because the redirection is executed with the privileges of the user executing sudo
, it will belong to this user (and not to root
as maybe expected): sudo echo foo > /tmp/xyz
sudo sh -c "echo foo > /tmp/xyz"
tee
in combination with sudo
. sudoreplay
. /etc/sudo.conf
is the configuration file for sudo
/var/run/sudo/ts
is the default directory where sudo
stores time stamp files. pkexec
).