English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Linux su command (full English name: switch user) is used to change the identity to another user, and in addition to root, the password of the user must be entered.
Permission to use: All users.
su [-fmp] [-c command] [-s shell] [--help] [--version] [-] [USER [ARG]]
Parameter Description:
Change account to root and exit after executing ls command to return to the original user
su -c ls root
Change account to root and pass -f Parameter for the New Executed Shell
su root -f
Change account to clsung and change working directory to clsung's home directory (home dir)
su - clsung
Switch User
[email protected]:~$ whoami //Show Current User hnlinux [email protected]:~$ pwd //Show 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 //Show Current User hnlinux [email protected]:~$ pwd //Show Current Directory /home/hnlinux [email protected]:~$ su - root //Switch to root User Password: [email protected]:/home/hnlinux# whoami root [email protected]:/home/hnlinux# pwd //Show Current Directory /root