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

前端 未结 26 1505
失恋的感觉
失恋的感觉 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 04:10

    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

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

    Try:

    ssh -t remotehost "sudo <cmd>"
    

    This will remove the above errors.

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

    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> 
    
    0 讨论(0)
  • 2020-11-22 04:14

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

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

    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
    
    0 讨论(0)
  • 2020-11-22 04:16

    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
      
    0 讨论(0)
提交回复
热议问题