[root@hf-01 ~]# visudo 會進入/etc/sudoers.tmp的配置文件中 97 ## Allow root to run any commands anywhere 98 root ALL=(ALL) ALL 99 hanfeng ALL=(ALL) /usr/bin/ls, /usr/bin/mv, /usr/bin/ls [root@hf-01 ~]#
[root@hf-01 ~]# su - hanfeng 上一次登陸:四 11月 2 03:52:44 CST 2017pts/0 上 [hanfeng@hf-01 ~]$ ls /root/ ls: 沒法打開目錄/root/: 權限不夠 [hanfeng@hf-01 ~]$ sudo /usr/bin/ls /root/ 在執行命令後,會提示輸入hanfeng用戶的密碼 We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. [sudo] password for hanfeng: 11.txt 234 33.txt ha.txt [hanfeng@hf-01 ~]$ ls /root/ 在hanfeng用戶下直接去執行會發現沒法打開/root/目錄 ls: 沒法打開目錄/root/: 權限不夠 [hanfeng@hf-01 ~]$ sudo /usr/bin/ls /root/ 11.txt 234 33.txt ha.txt [hanfeng@hf-01 ~]$ mv /root/ha.txt /root/haha.txt mv: 沒法打開目錄/root/: 權限不夠 [hanfeng@hf-01 ~]$ sudo /usr/bin/mv /root/ha.txt /root/haha.txt [hanfeng@hf-01 ~]$ 登出 [root@hf-01 ~]#
[root@hf-01 ~]# visudo [root@hf-01 ~]# su - user2 上一次登陸:四 11月 2 07:17:04 CST 2017pts/0 上 [user2@hf-01 ~]$ ls /root/ ls: 沒法打開目錄/root/: 權限不夠 [user2@hf-01 ~]$ sudo ls /root/ 11.txt 234 33.txt haha.txt [user2@hf-01 ~]$ sudo /usr/bin/ls /root/ 11.txt 234 33.txt haha.txt [user2@hf-01 ~]$ 登出 [root@hf-01 ~]#
## User Aliases ## These aren't often necessary, as you can use regular groups ## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname ## rather than USERALIAS # User_Alias ADMINS = jsmith, mikem
## Networking # Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient , /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig , /sbin/mii-tool
例子:this
[root@hf-01 ~]# visudo 進入到配置環境中 而後到 ## Networking 那一段落最後加上 HANFENG_CMD = /usr/bin/ls, /usr/bin/mv, /usr/bin/cat 並將用戶名hanfeng後面,去除那些絕對路徑命令,修改上HANFENG_CMD,而後保存退出 root ALL=(ALL) ALL hanfeng ALL=(ALL) HANFENG_CMD [root@hf-01 ~]# su - hanfeng 上一次登陸:四 11月 2 05:46:40 CST 2017pts/0 上 [hanfeng@hf-01 ~]$ sudo ls /root/ 這裏會發現能夠查看/root/目錄下的文件 [sudo] password for hanfeng: 11.txt 234 33.txt haha.txt [hanfeng@hf-01 ~]$ sudo ls /root/ 11.txt 234 33.txt haha.txt [hanfeng@hf-01 ~]$ sudo cat /root/haha.txt [hanfeng@hf-01 ~]$ 登出 [root@hf-01 ~]#
## Allows people in group wheel to run all commands 109 %wheel ALL=(ALL) ALL