When to use su
Use su to start a shell as another local account when policy permits. A login shell refreshes more of the account environment, which matters for home directories, startup files and command lookup.
Syntax
su [OPTIONS] [USER]Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Switch to test account
su - deployA login shell starts for the target account with its login environment.
Verify identity from another user
su - deploy -c 'id'The identity check runs as the target account and the command then exits.
Open Bash as another user
su -s /bin/bash deployA specific shell is requested, subject to account and system restrictions.
Notes and limitations
- su typically asks for the target account's password; PAM policy can change behavior.
- To exit a nested shell, run exit; on servers it is often more convenient to use the limited sudo.
Common questions and troubleshooting
Does su use my password or the target password?
That depends on authentication policy and privilege. On common local configurations it asks for the target account's password; do not assume sudo semantics.
Why does the environment differ after switching users?
Login and non-login modes initialise different variables and startup files. Verify identity, home directory and command path in the new shell.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man su.