How to fix 'sudo: no tty present and no askpass program specified' error?

前端 未结 26 2146
失恋的感觉
失恋的感觉 2020-11-22 03:36

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 sour

26条回答
  •  余生分开走
    2020-11-22 03:56

    For the reference, in case someone else encounter the same issue, I was stuck during a good hour with this error which should not happen since I was using the NOPASSWD parameter.

    What I did NOT know was that sudo may raise the exact same error message when there is no tty and the command the user try to launch is not part of the allowed command in the /etc/sudoers file.

    Here a simplified example of my file content with my issue:

    bguser ALL = NOPASSWD: \
        command_a arg_a, \
        command_b arg_b \
        command_c arg_c
    

    When bguser will try to launch "sudo command_b arg_b" without any tty (bguser being used for some daemon), then he will encounter the error "no tty present and no askpass program specified".

    Why?

    Because a comma is missing at the end of line in the /etc/sudoers file...

    (I even wonder if this is an expected behavior and not a bug in sudo since the correct error message for such case shoud be "Sorry, user bguser is not allowed to execute etc.")

提交回复
热议问题