su

From Gentoo Wiki
Jump to: navigation, search

Resources

The su (substitute user) command can be used to impersonate other users on the system. su is provided by the sys-apps/shadow package. It is also included with the sys-apps/util-linux package, but it is disabled in the ebuild to prevent a file collision with sys-apps/shadow.

Usage

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'
Note
It is best practice to encapsulate the commands following the -c option with either single or double quotes.

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

See also