Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup a SUDO_ASKPASS environment variable?

Tags:

java

shell

sudo

What does setting up a SUDO_ASKPASS environment variable mean? How do you do it? Where do I declare it?

I am trying to use a shell script to shutoff my computer after a couple of minutes and initiate this script with java.

like image 257
user1700434 Avatar asked Sep 26 '12 18:09

user1700434


People also ask

What is Sudo_askpass?

SUDO_ASKPASS. Specifies the path to a helper program used to read the password if no terminal is available or if the -A option is specified. SUDO_COMMAND. Set to the command run by sudo.

What is an Askpass helper?

If the -A (askpass) option is specified, a (possibly graphical) helper program is executed to read the user's password and output the password to the standard output. If the SUDO_ASKPASS environment variable is set, it specifies the path to the helper program.


1 Answers

So I am not sure I'd use $SUDO_ASKPASS for this. Basically the value of $SUDO_ASKPASS is to be an executable that will spit your password to standard out when invoked. So, if your password was 'foo', you could write a shell script as:

#!/bin/bash
echo 'foo'

and place it in ~/bin/pw.sh. Then you would set the environment variable and execute the command as so:

SUDO_ASKPASS=${HOME}/bin/pw.sh sudo shutdown -h now

that example assumes that you're on Darwin; shutdown behaves differently on different operating systems.

A more intelligent way of doing this (and more secure) is to use the NOPASSWD argument in /etc/sudoers. We would add a line like this:

jane ALL=NOPASSWD: /sbin/shutdown

This again assumes you're on a Mac. And that your name is Jane. Change that. This way sudo will not ask for a password when you issue the command /sbin/shutdown. The command to (properly) edit sudoers is visudo.

like image 158
jane arc Avatar answered Sep 19 '22 10:09

jane arc