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:43

After all alternatives, I found:

sudo -S <cmd>

The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.

Source

Above command still needs password to be entered. To remove entering password manually, in cases like jenkins, this command works:

echo <password> | sudo -S <cmd> 
查看更多
听够珍惜
3楼-- · 2018-12-31 10:44

I think I can help someone with my case.

First, I changed the user setting in /etc/sudoers referring to above answer. But It still didn't work.

myuser   ALL=(ALL) NOPASSWD: ALL
%mygroup  ALL=(ALL:ALL) ALL

In my case, myuser was in the mygroup.

And I didn't need groups. So, deleted that line.

(Shouldn't delete that line like me, just marking the comment.)

myuser   ALL=(ALL) NOPASSWD: ALL

It works!

查看更多
十年一品温如言
4楼-- · 2018-12-31 10:45

Try:

  1. Use NOPASSWD line for all commands, I mean:

    jenkins ALL=(ALL) NOPASSWD: ALL
    
  2. Put the line after all other lines in the sudoers file.

That worked for me (Ubuntu 14.04).

查看更多
余生无你
5楼-- · 2018-12-31 10:45

Login into your linux. Fire following commands. Be careful, as editing sudoer is a risky proposition.

$ sudo visudo

Once vi editor opens make the following changes:

  1. Comment out Defaults requiretty

    # Defaults    requiretty
    
  2. Go to the end of the file and add

    jenkins ALL=(ALL) NOPASSWD: ALL
    
查看更多
看风景的人
6楼-- · 2018-12-31 10:45

This worked for me:

echo "myuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

where your user is "myuser"

for a Docker image, that would just be:

RUN echo "myuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
查看更多
弹指情弦暗扣
7楼-- · 2018-12-31 10:45

Command sudo fails as it is trying to prompt on root password and there is no pseudo-tty allocated (as it's part of the script).

You need to either log-in as root to run this command or set-up the following rules in your /etc/sudoers (or: sudo visudo):

# Members of the admin group may gain root privileges.
%admin  ALL=(ALL) NOPASSWD:ALL

Then make sure that your user belongs to admin group (or wheel).

Ideally (safer) it would be to limit root privileges only to specific commands which can be specified as %admin ALL=(ALL) NOPASSWD:/path/to/program

查看更多
登录 后发表回答