su(1)
Switch to another user account, or become the superuser (root).
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
| Flag | What it does |
|---|---|
-l, --login | Start a login shell with the target user's full environment, home directory, and profile scripts |
-m, --preserve-environment | Preserve the current environment variables instead of loading the target user's environment |
-s SHELL, --shell=SHELL | Use the specified shell instead of the target user's default shell |
-c COMMAND | Execute a single command as the target user and exit, without starting an interactive shell |
-p, --preserve-groups | Preserve the current user's group memberships (useful with --preserve-environment) |
-w WHITELIST, --whitelist=WHITELIST | Whitelist environment variables to preserve from the calling environment |
-g GROUP, --group=GROUP | Specify a primary group for the new shell session |
--help | Display help message and exit |
Examples
Switch to root; prompts for root password and starts a non-login shell
suSwitch to root with a login shell, loading root's full profile and starting in root's home directory
su - rootSwitch to user alice with a login shell, loading her environment and home directory
su - aliceRun the 'id' command as user bob without starting an interactive shell, then exit
su -c 'id' bobSwitch to user alice but use /bin/bash as the shell regardless of her default
su -s /bin/bash aliceRun 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