What is the su Command?
If you want to temporarily access another user 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, the su command allows you to switch from one user account to another for a short time, so you can work with the permissions of that user.
Syntax:
su [option] [username]
Options:
-
-l → Full login mode. Switches to the target user along with their environment.
su - prabha
-
-c → Run a single command as the target user, then return to your original user.
su -c "ls /home/prabha" prabha
- --help → Shows help information about the su command.
Example : Switch to another user account
Current user: abha
User you want to switch to: prabha
Command:
su prabha
Output:
prabha@computer:~$
Explanation:
- Now you are logged in as prabha.
- To return to your original user, simply type exit or press Ctrl + D.
- Now you are back as abha.












