Su
Der Befehl su (substitute user) kann verwendet werden um die Berechtigung anderer Benutzer des Systems zu übernehmen.
Der Befehl wird vom Paket util-linux bereitgestellt, das standardmäßig die su USE flag aktiviert hat. Der Befehl su ist auch mit sys-apps/shadow verfügbar, das Ebenfalls die su flag besitzt. Vermeiden Sie die gleichzeitige Installation beider Befehle.
Mahnung
The use of su to access the user root is only permitted when the calling user is a member of the user group wheel.
In the next example the user john is added to the user group wheel.
root #usermod -aG wheel johnUsage
user $su --helpUsage:
su [options] [-] [<user> [<argument>...]]
Change the effective user ID and group ID to that of <user>.
A mere - implies -l. If <user> is not given, root is assumed.
Options:
-m, -p, --preserve-environment do not reset environment variables
-w, --whitelist-environment <list> don't reset specified variables
-g, --group <group> specify the primary group
-G, --supp-group <group> specify a supplemental group
-, -l, --login make the shell a login shell
-c, --command <command> pass a single command to the shell with -c
--session-command <command> pass a single command to the shell with -c
and do not create a new session
-f, --fast pass -f to the shell (for csh or tcsh)
-s, --shell <shell> run <shell> if /etc/shells allows it
-P, --pty create a new pseudo-terminal
-h, --help display this help
-V, --version display version
For more details see su(1).
Adopt root privileges
su will run commands as root by default. Since not specifying a username will cause su to ask for root privileges, the following command will run as root and halt the system:
user $su -c 'shutdown -h now'It is best practice to encapsulate the commands following the
-c option with either single or double quotes.Adopt another user's privileges
It is also possible to specify a user other than root to substitute commands. The following example will run the command echo as the user larry:
user $su -c 'echo "Moo to the Gentoo Wiki reader out there!"' larry