歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> xx is not in the sudoers file問題的解決方案

xx is not in the sudoers file問題的解決方案

日期:2017/3/1 16:56:11   编辑:關於Linux
xx is not in the sudoers file 問題解決的兩種方案如下。。。。。 兩種方法執行命令不同而已,原理其實一樣 www.2cto.com 方法一: 首先利用whereis 命令查找sudoers配置文件的目錄(默認會在/etc/sudoers) [root@localhost xiaofei]# whereis sudoers sudoers: /etc/sudoers /etc/sudoers.bak /usr/share/man/man5/sudoers.5.gz 然後需要su -切換到root用戶,更改/etc/sudoers的權限 [root@localhost xiaofei]# chmod u+w /etc/sudoers 然後就可以利用vi編輯器來把用戶添加到sudoers之中: [root@localhost xiaofei]# vi /etc/sudoers 然後找到root ALL=(ALL) ALL所在的位置,把所要添加的用戶添加到文件之中, 下面是添加完的結果: ## Allow root to run any commands anywhere root ALL=(ALL) ALL xiaofei ALL=(ALL) ALL (這一行是添加的內容,xiaofei是用戶名) 然後需要把sudoers 的寫權限去掉: [root@localhost xiaofei]# chmod u-w /etc/sudoers 如果不去掉寫權限,系統不允許執行suoders文件,運行sudo命令時會出現以下錯誤: sudo: /etc/sudoers is mode 0640, should be 0440 www.2cto.com 至此,在退出root用戶之後就可以利用sudo命令來執行超級用戶的權限了。 方法二: 首需要切換到root身份 $su - (注意有- ,這和su是不同的,在用命令"su"的時候只是切換到root,但沒有把root的環境變量傳過去,還是當前用戶的環境變量,用"su -"命令將環境變量也一起帶過去,就象和root登錄一樣) 然後 $visudo //切記,此處沒有vi和sudo之間沒有空格 1、移動光標,到最後一行 2、按a,進入append模式 3、輸入 your_user_name ALL=(ALL) ALL 4、按Esc 5、輸入“:wq” 這樣就把自己加入了sudo組,可以使用sudo命令了。
Copyright © Linux教程網 All Rights Reserved