Commands · Command

CommandLinuxmacOS

su

su [-] [username]

Switches to another user account within the current terminal session, prompting for that user's password (defaults to root if no username is given).

// FLAGS

-also -l/--login: start a full login shell with the target user's environment, not just their permissions

// EXAMPLE

su - — switches to the root user with root's full environment (PATH, home directory, etc.), after prompting for the root password.

// GOTCHA

Plain su (without the -) keeps your original environment variables and working directory — commands can behave unexpectedly since PATH and HOME still point at the original user, not the one you switched to.

// RELATED COMMANDS