Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

I created a user named shut so that whenever one logs in using that username the machine would shut down. For that I placed the below command in the end of the .profile.

exec sudo shutdown -h now

But this didn't serve the purpose. When the user shut logs in, rather than the machine shutting down, the login screen is coming back. So the user isn't able to log in but at the same time getting back the same login screen.

The reason I feel is that because password for the user shut isn't provided , the machine isn't shutting down. And because of exec, the login screen is coming back (which is fine).

Now to solve my work, I need a way so that it would automatically take my password when the above sudo command executes. I checked man sudo and I think -A option has to be used.

Following that man page, I ran

SUDO_ASKPASS=/home/ravbholua/pass.txt

export SUDO_ASKPASS

Then to check whether it's working, I ran

ravbholua@ravbholua-Aspire-5315:~$ sudo -A pwd

sudo: unable to run /home/ravbholua/pass.txt: Permission denied

From this output, it means this path file has to run and provide my password as output to sudo. What earlier I thought, it would take the password from this file named pass.txt, so I entered my password in this file. But no!!!!!!!

Any suggestions please!

share|improve this question

marked as duplicate by slm, Anthon, jasonwryan, rahmu, warl0ck Sep 29 '13 at 2:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
askubuntu.com/questions/155791/… –  Bob Sep 28 '13 at 16:12

1 Answer 1

up vote 4 down vote accepted

SUDO_ASKPASS is supposed to be a binary that prompts the user for a password. An example of a use for it would be to have an window pop up in a GUI asking the user to type in their password when they're using a GUI program. The man page says the following on it:

Specifies the path to a helper program used to read the password if no terminal is available or if the -A option is specified.

To do what you want, you probably want to edit your /etc/sudoers file to allow the 'shut' user to be able to run shutdown without specifying a password. The below line allows the 'shut' user to run '/sbin/shutdown -h now' and '/sbin/shutdown -r now' on 'ALL' machines.

shut    ALL = NOPASSWD: /sbin/shutdown -h now, /sbin/shutdown -r now

A more insecure option would be to use the '-S' option of sudo to read the password from stdin and echo the password to it like so:

echo "password" | sudo -S shutdown -h now
share|improve this answer
    
Great !! Many thanks for troubleshooting. –  Ravi Sep 29 '13 at 2:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.