Linux su命令用于变更为其他使用者的身份,除 root 外,需要键入该使用者的密码。
使用权限:所有使用者。
su [-fmp] [-c command ] [-s shell] [--help] [--version] [-] [USER [ARG]] |
参数说明:
变更帐号为 root 并在执行 ls 指令后退出变回原使用者
su -c ls root |
变更帐号为 root 并传入 -f 参数给新执行的 shell
su root -f |
变更帐号为 clsung 并改变工作目录至 clsung 的家目录(home dir)
su - clsung |
切换用户
hnlinux@edu.jb51.net:~$ whoami // 显示当前用户 hnlinux hnlinux@edu.jb51.net:~$ pwd // 显示当前目录 /home/hnlinux hnlinux@edu.jb51.net:~$ su root // 切换到root用户 密码: root@edu.jb51.net: /home/hnlinux # whoami root root@edu.jb51.net: /home/hnlinux # pwd /home/hnlinux |
切换用户,改变环境变量
hnlinux@edu.jb51.net:~$ whoami // 显示当前用户 hnlinux hnlinux@edu.jb51.net:~$ pwd // 显示当前目录 /home/hnlinux hnlinux@edu.jb51.net:~$ su - root // 切换到root用户 密码: root@edu.jb51.net: /home/hnlinux # whoami root root@edu.jb51.net: /home/hnlinux # pwd //显示当前目录 /root |