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

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

    No one told what could cause this error, in case of migration from one host to another, remember about checking hostname in sudoers file:

    So this is my /etc/sudoers config

    User_Alias      POWERUSER = user_name
    Cmnd_Alias SKILL = /root/bin/sudo_auth_wrapper.sh
    POWERUSER hostname=(root:root) NOPASSWD: SKILL
    

    if it doesn't match

    uname -a
    Linux other_hostname 3.10.17 #1 SMP Wed Oct 23 16:28:33 CDT 2013 x86_64 Intel(R) Core(TM) i3-4130T CPU @ 2.90GHz GenuineIntel GNU/Linux
    

    it will pop up this error:

    no tty present and no askpass program specified

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

    Make sure the command you're sudoing is part of your PATH.

    If you have a single (or multi, but not ALL) command sudoers entry, you'll get the sudo: no tty present and no askpass program specified when the command is not part of your path (and the full path is not specified).

    You can fix it by either adding the command to your PATH or invoking it with an absolute path, i.e.

    sudo /usr/sbin/ipset

    Instead of

    sudo ipset

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

    Other options, not based on NOPASSWD:

    • Start Netbeans with root privilege ((sudo netbeans) or similar) which will presumably fork the build process with root and thus sudo will automatically succeed.
    • Make the operations you need to do suexec -- make them owned by root, and set mode to 4755. (This will of course let any user on the machine run them.) That way, they don't need sudo at all.
    • Creating virtual hard disk files with bootsectors shouldn't need sudo at all. Files are just files, and bootsectors are just data. Even the virtual machine shouldn't necessarily need root, unless you do advanced device forwarding.
    0 讨论(0)
  • 2020-11-22 04:20

    For Ubuntu 16.04 users

    There is a file you have to read with:

    cat /etc/sudoers.d/README
    

    Placing a file with mode 0440 in /etc/sudoers.d/myuser with following content:

    myuser  ALL=(ALL) NOPASSWD: ALL
    

    Should fix the issue.

    Do not forget to:

    chmod 0440 /etc/sudoers.d/myuser
    
    0 讨论(0)
  • 2020-11-22 04:20

    I was able to get this done but please make sure to follow the steps properly. This is for the anyone who is getting import errors.

    Step1: Check if files and folders have got execute permission issue. Linux user use:

    chmod 777 filename
    

    Step2: Check which user has the permission to execute it.

    Step3: open terminal type this command.

    sudo visudo
    

    add this lines to the code below

    www-data ALL=(ALL) NOPASSWD:ALL
    nobody ALL=(ALL) NOPASSWD:/ALL
    

    this is to grant permission to execute the script and allow it to use all the libraries. The user generally is 'nobody' or 'www-data'.

    now edit your code as

    echo shell_exec('sudo -u the_user_of_the_file python your_file_name.py 2>&1');
    

    go to terminal to check if the process is running type this there...

    ps aux | grep python
    

    this will output all the process running in python.

    Add Ons: use the below code to check the users in your system

    cut -d: -f1 /etc/passwd
    

    Thank You!

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

    Try this one:

    echo '' | sudo -S my_command
    
    0 讨论(0)
提交回复
热议问题