Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

解決 sudo 報「user is not in the sudoers file」

普通使用者執行 sudo 時跳出這段訊息,代表該帳號沒有被授權:

[oracle@DBA2 fd]$ sudo ps -ef|grep dbw
[sudo] password for oracle:
oracle is not in the sudoers file.  This incident will be reported.

原因很直接:oracle 不在 sudo 的設定檔裡,因此無權使用 sudo。

解法:把帳號加進 sudoers

切換成 root,先讓 sudoers 可以被寫入(預設是唯讀):

[root@DBA2 etc]# chmod u+w sudoers
[root@DBA2 etc]# vi sudoers

在 root ALL=(ALL) ALL 那一行之後,仿照格式加上:

oracle  ALL=(ALL)  ALL

存檔後把權限改回原本的唯讀狀態,維持檔案的一致性:

[root@DBA2 etc]# chmod u-w sudoers
[root@DBA2 etc]# ll sudoers
-r--r----- 1 root root 3402 Sep  4 10:40 sudoers

驗證

[oracle@DBA2 ~]$ sudo ps -ef|grep dbw
[sudo] password for oracle:
oracle   3140     1  0 09:28 ?    00:00:06 ora_dbw0_orcl2
oracle  19299 17065  0 10:41 pts/2 00:00:00 grep dbw

小提醒:更推薦的做法是使用 visudo 編輯,它會在存檔前做語法檢查並鎖住檔案,避免手滑寫壞 sudoers 導致所有人都無法使用 sudo。另外,若要免密碼執行特定指令,可改用 oracle ALL=(ALL) NOPASSWD: /usr/bin/ps 這類最小權限寫法。

Copyright © Linux教程網 All Rights Reserved