English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
La commande Linux su (en anglais complet : switch user) est utilisée pour changer l'identité de l'utilisateur, à l'exception de root, il est nécessaire de saisir le mot de passe de cet utilisateur.
Autorisation d'utilisation : tous les utilisateurs.
su [-fmp] [-c command] [-s shell] [--help] [--version] [-] [USER [ARG]]
Explication des paramètres:
将账户变更为 root 并在执行 ls 指令后退出变回原使用者
su -c ls root
将账户变更为 root 并传递 -f 参数传递给新执行的 shell
su root -f
将账户变更为 clsung 并将工作目录变更为 clsung 的家目录(home dir)
su - clsung
切换用户
[email protected]:~$ whoami //显示当前用户 hnlinux [email protected]:~$ pwd //显示当前目录 /home/hnlinux [email protected]:~$ su root //切换到root用户 密码: [email protected]:/home/hnlinux# whoami root [email protected]:/home/hnlinux# pwd /home/hnlinux
切换用户,改变环境变量
[email protected]:~$ whoami //显示当前用户 hnlinux [email protected]:~$ pwd //显示当前目录 /home/hnlinux [email protected]:~$ su - root //切换到root用户 密码: [email protected]:/home/hnlinux# whoami root [email protected]:/home/hnlinux# pwd //显示当前目录 /root