How to fix 'sudo: no tty present and no askpas

2018-12-31 09:58发布

I am trying to compile some sources using a makefile. In the makefile there is a bunch of commands that need to be ran as sudo.

When I compile the sources from a terminal all goes fine and the make is paused the first time a sudo command is ran waiting for password. Once I type in the password, make resumes and completes.

But I would like to be able to compile the sources in NetBeans. So, I started a project and showed netbeans where to find the sources, but when I compile the project it gives the error:

sudo: no tty present and no askpass program specified

The first time it hits a sudo command.

I have looked up the issue on the internet and all the solutions I found point to one thing: disabling the password for this user. Since the user in question here is root. I do not want to do that.

Is there any other solution?

标签: linux sudo tty
21条回答
临风纵饮
2楼-- · 2018-12-31 10:48

In Jenkins:

echo '<your-password>' | sudo -S command

Eg:-

echo '******' | sudo -S service nginx restart

You can use Mask Password Plugin to hide your password

查看更多
心情的温度
3楼-- · 2018-12-31 10:48

Running shell scripts that have contain sudo commands in them from jenkins might not run as expected. To fix this, follow along

Simple steps:

  1. On ubuntu based systems, run " $ sudo visudo "

  2. this will open /etc/sudoers file.

  3. If your jenkins user is already in that file, then modify to look like this:

jenkins ALL=(ALL) NOPASSWD: ALL

  1. save the file

  2. Relaunch your jenkins job

  3. you shouldnt see that error message again :)

查看更多
低头抚发
4楼-- · 2018-12-31 10:48

I was getting this error because I had limited my user to only a single executable 'systemctl' and had misconfigured the visudo file.

Here's what I had:

jenkins ALL=NOPASSWD: systemctl

However, you need to include the full path to the executable, even if it is on your path by default, for example:

jenkins ALL=NOPASSWD: /bin/systemctl

This allows my jenkins user to restart services but not have full root access

查看更多
登录 后发表回答