我試圖讓我的詹金斯用戶能夠使用 www-data 用戶執行腳本,所以我嘗試添加
jenkins ALL=NOPASSWD:ALL
在我的 sudoers 文件末尾,但它不起作用,當我使用命令時詢問密碼
sudo -u www-data /path/to/script.sh
我還嘗試在 /etc/sudoers.d/ 下的文件中添加該行,但沒有幫助。
這是我今天的 sudoers 文件
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
#Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) 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
# User alias specification
我在很多論壇上看到,必須在 sudoers 文件的末尾添加該行,我這樣做了,但從未起作用。你有好主意嗎?
答案1
找到以下行:
%sudo ALL=(ALL:ALL) ALL
將其替換為這一行:
%sudo ALL=(ALL:ALL) NOPASSWD: ALL