我花了几天时间设置文件/etc/sudoers
,以便能够向用户jenkins
授予root权限。我在我的服务器上安装了Jenkins,因为我主持了几个项目,包括symfony,ionic,neo4j等等......问题是我无法用离子构建项目,我得到这个错误:sudo: no tty present and no askpass program specified.
这是我的/ etc / 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
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
jenkins ALL=(ALL) NOPASSWD: ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
答案 0 :(得分:26)
我在问题的评论中测试了@Jayan描述的解决方案。您必须在文件末尾包含新行:
解决方案:https://stackoverflow.com/a/24648413/54506
#
# 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
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
jenkins ALL=(ALL) NOPASSWD: ALL
答案 1 :(得分:2)
您很可能在sudoers文件中添加了错误的用户。这也发生在我身上,在sudoers文件中添加条目的解决方案对我来说并不适合。您需要知道jenkins用于执行命令的实际用户。为此,您可以使用以下命令在jenkins中添加构建步骤(Execute shell):
whoami
然后再次尝试运行jenkins作业,在控制台输出中,您将看到jenkins用于执行命令的用户。然后,您需要将此用户添加到您的sudoers文件中。例如,如果用户是' tomcat',您将在sudoers文件的末尾添加以下行:
tomcat ALL=(ALL) NOPASSWD: ALL
参考:http://techrofile.com/jenkins-sudo-no-tty-present-and-no-askpass-program-specified-with-nopasswd/
答案 2 :(得分:0)