Jenkins sudo:不存在tty,也没有使用NOPASSWD指定askpass程序
我花了几天时间设置文件Jenkins sudo:不存在tty,也没有使用NOPASSWD指定askpass程序,jenkins,sudo,Jenkins,Sudo,我花了几天时间设置文件/etc/sudoers,以便能够将root权限授予用户jenkins。我在我的服务器上安装了Jenkins,因为我用symfony、ionic、neo4j等主持了几个项目。。。问题是,我无法使用ionic在项目中进行构建,我得到以下错误:sudo:不存在tty,也没有指定askpass程序。这是我的/etc/sudoers文件的内容: # # This file MUST be edited with the 'visudo' command as root. # # P
/etc/sudoers
,以便能够将root权限授予用户jenkins
。我在我的服务器上安装了Jenkins,因为我用symfony、ionic、neo4j等主持了几个项目。。。问题是,我无法使用ionic在项目中进行构建,我得到以下错误:sudo:不存在tty,也没有指定askpass程序。
这是我的/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
tomcat ALL=(ALL) NOPASSWD: ALL
我已经测试了@Jayan在问题评论中描述的解决方案。必须在文件末尾包含新行: 解决方案:
这很可能是您向sudoers文件添加了错误的用户。这种情况也发生在我身上,在sudoers文件中添加条目的解决方案对我不起作用。您需要知道jenkins用来执行命令的实际用户。为此,您可以使用以下命令在jenkins中添加构建步骤(执行shell):
whoami
然后再次尝试运行jenkins作业,在控制台输出中,您将看到jenkins用来执行命令的用户。然后需要将此用户添加到sudoers文件中。例如,如果用户是“tomcat”,您将在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
tomcat ALL=(ALL) NOPASSWD: ALL
参考:这只是一个回应,详细说明了解决问题的步骤 首先,找出Jenkins GUI使用哪个用户来执行bash shell脚本 在可执行shell>立即保存并生成中选择项目>配置>输入
whoami
。
在生成历史记录中查看结果>单击控制台输出
用户可以是tomcat或jenkins或其他任何人
SSH到Jenkins服务器
sudo su
visudo
tomcat ALL=(ALL)NOPASSWD:ALL
#如果显示的用户是tomcat
请参阅(它谈到了一行应该是sudoers中的最后一行…)请记住,那些
sudoers
设置需要在正在生成的特定节点上设置,而不需要是主节点。谢谢whoami
和howto at为我解决了这个问题。将jenkins ALL=(ALL)NOPASSWD:ALL添加到sudoers文件就像一个符咒,谢谢你。这真是令人惊讶的没有bueno!如果任何形状或形式的jenkins实例都易受攻击,攻击者将获得对主机的完全访问权限。允许任何服务(特别是那些有交互语言的服务)根访问是个坏主意。改用setcap!