原帖位址:http://blog.sina.com.cn/s/blog_4ef045ab0100j59t.html
我用的是redhat5.4,在一般使用者下執行sudo指令提示llhtiger is not in the sudoers file. This incident will be reported.解決方法:
一、$whereis sudoers -------找出檔案所在的位置,預設都是/etc/sudoers
二、 #chmod u+w /etc/sudoers 以超級使用者登入su -root ,修改檔案權限即添加檔案擁有這的寫權限 限,ls -al /etc/sudoers 可以檢視原檔案的權限。
三、vim /etc/sudoers 編輯檔案,在root ALL=(ALL)ALL行下添加XXX ALL=(ALL)ALL,XXX為你的使用者名。添加方法:找到root行,按下”i“鍵進入編輯模式添加即可!編輯好後esc鍵進入一般模式,“:wq"儲存退出!
最後, #chmod u-w /etc/sudoers 回到檔案的原權限!
下面這個稍微詳細一點:
在ubuntu中由于禁用了root使用者,預設情況下會把安裝系統時建立的使用者添加到sudoers中。但在redhat和centos中并沒有把任何root使用者之外的使用者預設的添加到sudoers之中。這樣我們在執行sudo 指令時就會出現xxx is not in the sudoers file. This incident will be reported.這樣的錯誤輸出。現在為了安全起見比較提倡使用普通使用者做日常操作,而在需要超級使用者的時候使用sudo 來做,這樣,我們就有必要把一些使用者添加到sudoers之中。
其實把使用者添加到sudoers之中很簡單。
首先利用whereis 指令查找sudoers配置檔案的目錄(預設會在/etc/sudoers)
[[email protected] xiaofei]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.bak /usr/share/man/man5/sudoers.5.gz
然後需要切換到root使用者,更改/etc/sudoers的權限
[[email protected] xiaofei]# chmod u+w /etc/sudoers
然後就可以利用vi編輯器來把使用者添加到sudoers之中
[[email protected] xiaofei]# vi /etc/sudoers
然後找到root ALL=(ALL) ALL所在的位置,把所要添加的使用者添加到檔案之中,
順便提一下vi編輯器的用法。剛進入vi編輯器的時候牌指令行模式,這時可以通過方向鍵來移動光标,找到要編輯的位置之後按下“i”,然後就進入了插入模 式,這時候你可以輸入或删除字元。編輯完成之後按“esc”鍵退出插入模式,進入指令行模式,這時候按“:”可以進入末行模式,輸入“wq”儲存并退出。
下面是添加完的結果。
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
xiaofei ALL=(ALL) ALL (這一行是添加的内容,xiaofei是我的使用者名)
然後需要把sudoers 的寫權限去掉(否則系統不允許執行suoders檔案):
[[email protected] xiaofei]# chmod u-w /etc/sudoers
至此,在退出root使用者之後就可以利用sudo指令來執行超級使用者的權限了。