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

前端 未结 26 1603
失恋的感觉
失恋的感觉 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

    Granting the user to use that command without prompting for password should resolve the problem. First open a shell console and type:

    sudo visudo
    

    Then edit that file to add to the very end:

    username ALL = NOPASSWD: /fullpath/to/command, /fullpath/to/othercommand
    

    eg

    john ALL = NOPASSWD: /sbin/poweroff, /sbin/start, /sbin/stop
    

    will allow user john to sudo poweroff, start and stop without being prompted for password.

    Look at the bottom of the screen for the keystrokes you need to use in visudo - this is not vi by the way - and exit without saving at the first sign of any problem. Health warning: corrupting this file will have serious consequences, edit with care!

    0 讨论(0)
  • 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.")

    0 讨论(0)
  • 2020-11-22 03:58

    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

    0 讨论(0)
  • 2020-11-22 03:59

    Although this question is old, it is still relevant for my more or less up-to-date system. After enabling debug mode of sudo (Debug sudo /var/log/sudo_debug all@info in /etc/sudo.conf) I was pointed to /dev: "/dev is world writable". So you might need to check the tty file permissions, especially those of the directory where the tty/pts node resides in.

    0 讨论(0)
  • 2020-11-22 04:00

    If by any chance you came here because you can't sudo inside the Ubuntu that comes with Windows10

    1. Edit the /etc/hosts file from Windows (with Notepad), it'll be located at: %localappdata\lxss\rootfs\etc, add 127.0.0.1 WINDOWS8, this will get rid of the first error that it can't find the host.

    2. To get rid of the no tty present error, always do sudo -S <command>

    0 讨论(0)
  • 2020-11-22 04:01

    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).

    0 讨论(0)
提交回复
热议问题