$linuxjunkies
>

su(1)

Switch to another user account, or become the superuser (root).

UbuntuDebianFedoraArch

Synopsis

su [OPTION]... [USER [ARGUMENT]...]

Description

The su command switches the current shell session to a different user account. When invoked without arguments, it switches to the root user. A password prompt appears unless the calling user is already root. After authentication, a new shell is started with the target user's environment and permissions.

By default, su starts a non-login shell, preserving the current environment. Use -l or --login to start a login shell, which loads the target user's full profile and working directory.

Common options

FlagWhat it does
-l, --loginStart a login shell with the target user's full environment, home directory, and profile scripts
-m, --preserve-environmentPreserve the current environment variables instead of loading the target user's environment
-s SHELL, --shell=SHELLUse the specified shell instead of the target user's default shell
-c COMMANDExecute a single command as the target user and exit, without starting an interactive shell
-p, --preserve-groupsPreserve the current user's group memberships (useful with --preserve-environment)
-w WHITELIST, --whitelist=WHITELISTWhitelist environment variables to preserve from the calling environment
-g GROUP, --group=GROUPSpecify a primary group for the new shell session
--helpDisplay help message and exit

Examples

Switch to root; prompts for root password and starts a non-login shell

su

Switch to root with a login shell, loading root's full profile and starting in root's home directory

su - root

Switch to user alice with a login shell, loading her environment and home directory

su - alice

Run the 'id' command as user bob without starting an interactive shell, then exit

su -c 'id' bob

Switch to user alice but use /bin/bash as the shell regardless of her default

su -s /bin/bash alice

Run ls command as alice with a login shell environment, then exit

su - alice -c 'ls /home/alice'

Switch to alice with a login shell but preserve the current environment variables

su -l -m alice

Related commands