解決CentOS下提示:xx is not in the sudoers file相關問題

來源:互聯網
上載者:User

解決CentOS下提示:xx is not in the sudoers file相關問題

我用的是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)
[root@localhost xiaofei]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.bak /usr/share/man/man5/sudoers.5.gz
然後需要切換到root使用者,更改/etc/sudoers的許可權
[root@localhost xiaofei]# chmod u+w /etc/sudoers
然後就可以利用vi編輯器來把使用者添加到sudoers之中
[root@localhost xiaofei]# vi /etc/sudoers
然後找到rootALL=(ALL)ALL所在的位置,把所要添加的使用者添加到檔案之中,

順便提一下vi編輯器的用法。剛進入vi編輯器的時候牌命令列模式,這時可以通過方向鍵來移動游標,找到要編輯的位置之後按下“i”,然後就進入了插入模 式,這時候你可以輸入或刪除字元。編輯完成之後按“esc”鍵退出插入模式,進入命令列模式,這時候按“:”可以進入末行模式,輸入“wq”儲存並退出。

下面是添加完的結果。
## Allow root to run any commands anywhere
rootALL=(ALL)ALL
xiaofei ALL=(ALL)ALL(這一行是添加的內容,xiaofei是我的使用者名稱)
然後需要把sudoers 的寫入權限去掉(否則系統不允許執行suoders檔案):
[root@localhost xiaofei]# chmod u-w /etc/sudoers
至此,在退出root使用者之後就可以利用sudo命令來執行超級使用者的許可權了。
原帖地址:http://blog.sina.com.cn/s/blog_4ef045ab0100j59t.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.