
我正在嘗試執行一些第三方安裝程式腳本(ansible tower setup.sh),該腳本需要以 root 身分或透過 sudo 啟動,因為某些命令依賴 root 權限。然而有些腳本執行期間的命令嘗試 sudo。不要問我為什麼,我認為安裝腳本是共同努力的結果,但存在一些不一致的地方...
所以腳本失敗了,我可以重現它。每當嘗試以 root 身分發出 sudo 時,我都會遇到這個奇怪的錯誤,例如
root@machine:/home/someuser: sudo echo 1
root is not allowed to run sudo on <FQDN here>. This incident will be reported.
在我之前使用 Ubuntu 的經驗中,我從未見過這樣的事情(公平地說,目前在 Google 上也沒有見過。)
由於無法找到所有位置並將腳本轉換為不呼叫 sudo,因此我必須找到一種方法來讓 root 使用者能夠執行 sudo。我正在使用的 Ubuntu 16.04 伺服器是由該公司的私有雲供應商在網域內以一種奇特的方式配置的(不知道這是否重要)。
我的 /etc/sudoers 看起來像這樣:
#
# This file MUST be edited with the 'visudo' command as root.
# more bla bla
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
+unixadmin,+unixadminext ALL= NOPASSWD: ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
關於須藤:
root@machine:/home/someuser# which sudo
/usr/bin/sudo
root@machine:/home/someuser# ll /usr/bin/sudo
-rwsr-xr-x 1 root root 140816 Jun 7 2017 /usr/bin/sudo*
我缺什麼?
我將 root 用戶新增到 sudo 群組,但並沒有解決問題。
答案1
作為 root,運行groups
- Root 不在 sudo 組中,因為為什麼它需要在 sudo 組中?
至於如何修復它,您可以將 root 新增至 sudo 群組,或者您可以檢查執行 sudo 的任何腳本(您已經將其視為解決特定問題的可能性,但它可能是其他人的解決方案。
將 root 新增到 sudo 群組:
(作為根)usermod -a -G sudo root