MySQL jenkins 在重新启动我的 sql 时失败“sudo:没有 tty 存在并且没有指定 askpass 程序抱歉,再试一次。”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16408877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:32:51  来源:igfitidea点击:

jenkins fails while restarting my sql "sudo: no tty present and no askpass program specified Sorry, try again."

mysqlamazon-web-servicesjenkins

提问by Raghvendra Singh

I just configured jenkins and in the pre-build steps i am trying to restart jenkins but i end up with the following error

我刚刚配置了 jenkins,在预构建步骤中,我试图重新启动 jenkins,但最终出现以下错误

Commencing build of Revision c5b9f8daac092efc5396d80f568a2cf89ae8b697 (origin/HEAD, origin/master)
Checking out Revision c5b9f8daac092efc5396d80f568a2cf89ae8b697 (origin/HEAD, origin/master)
No change to record in branch origin/HEAD
No change to record in branch origin/master
[webapp] $ /bin/sh -xe /tmp/hudson5215632082686866774.sh
+ sudo /etc/init.d/mysql restart
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
Build step 'Execute shell' marked build as failure
Finished: FAILURE

I googled and saw some answers at Jenkins out of nowhere starts failing with sudo: no tty present and no askpass program specified

用谷歌搜索并在Jenkins 上看到了一些答案突然开始以 sudo 失败:没有 tty 存在并且没有指定 askpass 程序

But unfortunately that didn't help me

但不幸的是,这对我没有帮助

My /etc/sudoers looks like this

我的 /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        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

# Members of the admin group may gain root privileges
%admin ALL=(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

回答by Barak

The "no tty present" error indicates that you have the 'requiretty' setting in your sudoers file. In your case, it is probably in /etc/sudoers.d. Once this line is there, it does not matter what group you are in - sudo will require a tty whenever it is executed.

“不存在 tty”错误表明您的 sudoers 文件中有“requiretty”设置。在您的情况下,它可能在 /etc/sudoers.d 中。一旦有了这一行,无论您在哪个组中都无关紧要 - sudo 每次执行时都需要一个 tty。

To get around this, you need to either remove (or comment out) the requiretty line in the configuration file, or add a line to exclude your user from the requiretty setting. You can see how to do that here: Disable requiretty per user

要解决此问题,您需要删除(或注释掉)配置文件中的 requiretty 行,或者添加一行以从 requiretty 设置中排除您的用户。您可以在此处查看如何执行此操作: Disable requiretty per user

回答by Marwa Hack

By adding the following: Defaults:username !authenticate to your /etc/sudoers you should not get the error but this username will be accessible without asking for a password

通过添加以下内容: Defaults:username !authenticate to your /etc/sudoers 您应该不会收到错误,但无需输入密码即可访问此用户名

回答by Prasun

Please use the "id" command and paste the output. Only if you are in admin group then you don't need password but for all other even though you have access but you need to type the sudo password. In this case sudo doesn't have a tty to ask for the password and hence the error.

请使用“id”命令并粘贴输出。仅当您在 admin 组中时,您才不需要密码,但对于所有其他人,即使您有权访问,但您需要输入 sudo 密码。在这种情况下,sudo 没有 tty 来询问密码,因此会出现错误。

One solution could be, don't use sudo only for mysql restart, instead run the entire script as sudo "sudo {your script path}" in this case sudo will have the terminal to ask for the password.

一种解决方案可能是,不要仅将 sudo 用于 mysql 重启,而是将整个脚本作为 sudo "sudo {your script path}" 运行,在这种情况下,sudo 将让终端要求输入密码。