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

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

    This error may also arise when you are trying to run a terminal command (that requires root password) from some non-shell script, eg sudo ls (in backticks) from a Ruby program. In this case, you can use Expect utility (http://en.wikipedia.org/wiki/Expect) or its alternatives.
    For example, in Ruby to execute sudo ls without getting sudo: no tty present and no askpass program specified, you can run this:

    require 'ruby_expect'
    
    exp = RubyExpect::Expect.spawn('sudo ls', :debug => true)
    exp.procedure do
        each do
            expect "[sudo] password for _your_username_:" do
                send _your_password_
            end
        end
    end
    

    [this uses one of the alternatives to Expect TCL extension: ruby_expect gem].

提交回复
热议问题