詳解Linux下的sudo及其配置文件/etc/sudoers的詳細(xì)配置
1.sudo介紹
sudo是linux下常用的允許普通用戶使用超級(jí)用戶權(quán)限的工具,允許系統(tǒng)管理員讓普通用戶執(zhí)行一些或者全部的root命令,如halt,reboot,su等等。這樣不僅減少了root用戶的登陸 和管理時(shí)間,同樣也提高了安全性。Sudo不是對(duì)shell的一個(gè)代替,它是面向每個(gè)命令的。
它的特性主要有這樣幾點(diǎn):
§ sudo能夠限制用戶只在某臺(tái)主機(jī)上運(yùn)行某些命令。
§ sudo提供了豐富的日志,詳細(xì)地記錄了每個(gè)用戶干了什么。它能夠?qū)⑷罩緜鞯街行闹鳈C(jī)或者日志服務(wù)器。
§ sudo使用時(shí)間戳文件來執(zhí)行類似的“檢票”系統(tǒng)。當(dāng)用戶調(diào)用sudo并且輸入它的密碼時(shí),用戶獲得了一張存活期為5分鐘的票(這個(gè)值可以在編譯的時(shí)候改變)。
§ sudo的配置文件是sudoers文件,它允許系統(tǒng)管理員集中的管理用戶的使用權(quán)限和使用的主機(jī)。它所存放的位置默認(rèn)是在/etc/sudoers,屬性必須為0411。
2.配置文件/etc/sudoers
它的主要配置文件是sudoers,linux下通常在/etc目錄下,如果是solaris,缺省不裝sudo的,編譯安裝后通常在安裝目錄的 etc目錄下,不過不管sudoers文件在哪兒,sudo都提供了一個(gè)編輯該文件的命令:visudo來對(duì)該文件進(jìn)行修改。強(qiáng)烈推薦使用該命令修改 sudoers,因?yàn)樗鼤?huì)幫你校驗(yàn)文件配置是否正確,如果不正確,在保存退出時(shí)就會(huì)提示你哪段配置出錯(cuò)的。
言歸正傳,下面介紹如何配置sudoers
首先寫sudoers的缺省配置:
############################################################# # sudoers file. # # This file MUST be edited with the 'visudo' command as root. # # See the sudoers man page for the details on how to write a sudoers file. # # Host alias specification # User alias specification # Cmnd alias specification # Defaults specification # User privilege specification root ALL=(ALL) ALL # Uncomment to allow people in group wheel to run all commands # %wheel ALL=(ALL) ALL # Same thing without a password # %wheel ALL=(ALL) NOPASSWD: ALL # Samples # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom # %users localhost=/sbin/shutdown -h now ##################################################################
1. 最簡(jiǎn)單的配置,讓普通用戶support具有root的所有權(quán)限 
執(zhí)行visudo之后,可以看見缺省只有一條配置: 
root    ALL=(ALL) ALL 
那么你就在下邊再加一條配置: 
support ALL=(ALL) ALL
這樣,普通用戶support就能夠執(zhí)行root權(quán)限的所有命令
以support用戶登錄之后,執(zhí)行: 
sudo su - 
然后輸入support用戶自己的密碼,就可以切換成root用戶了
2. 讓普通用戶support只能在某幾臺(tái)服務(wù)器上,執(zhí)行root能執(zhí)行的某些命令 
首先需要配置一些Alias,這樣在下面配置權(quán)限時(shí),會(huì)方便一些,不用寫大段大段的配置。Alias主要分成4種 
Host_Alias Cmnd_Alias User_Alias Runas_Alias
1) 配置Host_Alias:就是主機(jī)的列表 
Host_Alias      HOST_FLAG = hostname1, hostname2, hostname3 
2) 配置Cmnd_Alias:就是允許執(zhí)行的命令的列表 
新聞熱點(diǎn)
疑難解答
圖片精選