Easy Tutorial
❮ Linux Comm Bunzip2 Linux Shell ❯

Linux su Command

Linux Command Manual

The Linux su (full spelling in English: switch user) command is used to change to the identity of another user, except for root, the password of that user needs to be entered.

Usage permission: All users.

Syntax

su [-fmp] [-c command] [-s shell] [--help] [--version] [-] [USER [ARG]]

Parameter Description:

Examples

Change the account to root and execute the ls command before exiting and switching back to the original user
su -c ls root

Change the account to root and pass the -f parameter to the newly executed shell
su root -f

Change the account to clsung and change the working directory to clsung's home directory
su - clsung

Switch user
[email protected]:~$ whoami //Display current user
hnlinux
[email protected]:~$ pwd //Display current directory
/home/hnlinux
[email protected]:~$ su root //Switch to root user
Password: 
[email protected]:/home/hnlinux# whoami 
root
[email protected]:/home/hnlinux# pwd
/home/hnlinux

Switch user, change environment variables
[email protected]:~$ whoami //Display current user
hnlinux
[email protected]:~$ pwd //Display current directory
/home/hnlinux
[email protected]:~$ su - root //Switch to root user
Password: 
[email protected]:/home/hnlinux# whoami 
root
[email protected]:/home/hnlinux# pwd //Display current directory
/root

Linux Command Manual

❮ Linux Comm Bunzip2 Linux Shell ❯