[root@localhost ~]# id
uid=0(root) gid=0(root) 组=0(root)
[root@localhost ~]# whoami
root
[root@localhost ~]# su - test
上一次登录:四 8月 2 22:33:52 CST 2018pts/0 上
[test@localhost ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/test/.local/bin:/home/test/bin
[test@localhost ~]$ exit
登出
[root@localhost ~]# su test
[test@localhost root]$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[test@localhost root]$ exit
exit
[root@localhost ~]# su - test
上一次登录:四 8月 2 22:46:07 CST 2018pts/0 上
[test@localhost ~]$ su -
密码:
上一次登录:四 8月 2 21:39:44 CST 2018从 192.168.127.1pts/0 上
[root@localhost ~]# id
uid=0(root) gid=0(root) 组=0(root)
[root@localhost ~]# su --c "touch 11.txt" test
touch: 无法创建"11.txt": 权限不够
[root@localhost ~]# su --c "touch /tmp/1.txt" test
[root@localhost ~]# ls -l /tmp/1.txt
-rw-r--r-- 1 test test1 0 8月 2 22:47 /tmp/1.txt
[root@localhost ~]# visudo
...
...
root ALL=(ALL) ALL
test ALL=(ALL) NOPASSWD: /usr/bin/cat, /usr/bin/mv, /usr/bin/ls
...
...
# Host_Alias FILESERVERS = fs1, fs2
# User_Alias ADMINS = root, test
# Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping
test Host_Alias=(User_Alias) Cmnd_Alias NETWORKING
[root@localhost ~]# su - test
上一次登录:四 8月 2 22:59:30 CST 2018pts/0 上
[test@localhost ~]$ ls /root/
ls: 无法打开目录/root/: 权限不够
[test@localhost ~]$ sudo ls /root/
1.txt.bak anaconda-ks.cfg package-lock.json
[test@localhost ~]$ sudo cat /root/
cat: /root/: 是一个目录
[test@localhost ~]$ sudo cat /root/1.txt.bak
123