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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With