這是本文件的舊版!
通常在在系統管理時,要使用root所具有的權限都會使用su 或 su - ,但使用此方式必須先知道root密碼才能得到完整的權限。 那sudo就與su不同,sudo是以委派指定使用者方式,限定取得部份權限,而且事先不用知道root密碼,只要使用者自己的密碼即可取得root部份權限。
指定委派帳號 在哪一台機器=(換成哪一個帳號) 使用哪些指令
#visud
#andy 使用sudo在任何機器上,可以換成任何帳號,使用任何指令來控制系統。另外,沒給定(ALL),預設是換成root。 andy ALL=(ALL) ALL #使用者編組。jsmith,mikem為一組,別名為ADMINS(別名為大寫) # User_Alias ADMINS = jsmith, mikem #主機編組。host1.QQin.com, host2.QQin.com為一組,別名為MAILSERVERS(別名為大寫)。 Host_Alias MAILSERVERS = host1.QQin.com, host2.QQin.com #指令編組。/sbin/service, /sbin/chkconfig為一組,別名為SERVICES(別名為大寫)。 Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig #群組名為wheel 使用sudo在任何機器上,可以換成任何帳號,使用任何指令來控制系統。 %wheel ALL=(ALL) ALL #假若用sudo 不打密碼,在任何機器上,使用任何指令來控制系統。 # %wheel ALL=(ALL) NOPASSWD: ALL
在使用者student,betty 可以在任何機器上使用 sudo /etc/init.d/http 及chkconfig
未設定sudo之前 [student@location ~]$/etc/init.d/httpd start Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:80 (13)Permission denied: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs [student@location ~]$ chkconfig --level 35 httpd on chkconfig --level 35 httpd on You do not have enough privileges to perform this operation.
#visudo User_Alias TESTS = student,betty Cmnd_Alias CMDS = /etc/init.d/httpd,/sbin/chkconfig TESTS ALL=CMDS
測試
[student@location ~]$ sudo /etc/init.d/httpd start [sudo] password for student: (鍵入student 自己的密碼) Starting httpd: [ OK ]
[student@location ~]$ sudo chkconfig --level 35 httpd on [sudo] password for student: (鍵入student 自己的密碼) betty 同理也是一樣情況