Stands for substitute user. This command is used to switch user and lets exceuting command with the privilage of that user. It simplifies, typically for administrator, to manage users. Instead of logging to shell for separate users and sessions, admin can login with their own account and switch to sepcific user with their username.
General syntax for
$ su [OPTIONS] [USER [ARGUMENT...]]
Login with a different user account
Pass the username to the
su command, and it will provide a login session when the password has been verified.
Example: Login with a different username newone.
Login with a different user account + run a command
su [username] -c [command]
-c option allows you to run a particular command under a different user account and display the results in the current login session.
Example: Running the
ls command under another user account newone and displaying it in the ubuntu login session.
Specify the shell
su -s /bin/[shell]
-s option to change an existing default shell to a different one.
Example: Using the command to open the root user account in the Z shell (zsh).
Preserve user account environment
su Ã¢ÂÂp [another_user]
-p option allows you to keep the environment of the current user account.
Example: Switching username user to user newone. And displaying the home directory to show that it remains the same.