Linux 教程
Linux su命令用于變更為其他使用者的身份,除 root 外,需要鍵入該使用者的密碼。
使用權(quán)限:所有使用者。
su [-fmp] [-c command] [-s shell] [--help] [--version] [-] [USER [ARG]]
參數(shù)說(shuō)明:
變更帳號(hào)為 root 并在執(zhí)行 ls 指令后退出變回原使用者
su -c ls root
變更帳號(hào)為 root 并傳入 -f 參數(shù)給新執(zhí)行的 shell
su root -f
變更帳號(hào)為 clsung 并改變工作目錄至 clsung 的家目錄(home dir)
su - clsung
切換用戶(hù)
hnlinux@json.cn:~$ whoami //顯示當(dāng)前用戶(hù) hnlinux hnlinux@json.cn:~$ pwd //顯示當(dāng)前目錄 /home/hnlinux hnlinux@json.cn:~$ su root //切換到root用戶(hù) 密碼: root@json.cn:/home/hnlinux# whoami root root@json.cn:/home/hnlinux# pwd /home/hnlinux
切換用戶(hù),改變環(huán)境變量
hnlinux@json.cn:~$ whoami //顯示當(dāng)前用戶(hù) hnlinux hnlinux@json.cn:~$ pwd //顯示當(dāng)前目錄 /home/hnlinux hnlinux@json.cn:~$ su - root //切換到root用戶(hù) 密碼: root@json.cn:/home/hnlinux# whoami root root@json.cn:/home/hnlinux# pwd //顯示當(dāng)前目錄 /root其他擴(kuò)展