Definition:
su = switch user
If you want temporary access to another account, you use the su command.
For example, if you are logged in as user abha and want to switch to user prabha, you type:
su prabha
In simple words, it helps you jump from one account to another for a short time, so that you can work as that user.
Syntax:
su [option] [username]
Options:
-
- or -l → Full login mode. Switches to the target user along with their environment.
Example:su - prabha -
-c → Run a single command as the target user, then return to your original user.
Example:su -c "ls /home/prabha" prabha -
--help → Shows help information about the
sucommand.
Example:
Current user: abha
User you want to switch to: prabha
Command:
su prabha
Now you are in as Prabha.
To return to your original user, simply type:
exit
or press Ctrl + D.
Now you are back as Abha.
