1

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!

Ravi
  • 3,823

1 Answers1

4

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