Poweroff without a password

August 21, 2011

Ever find it strange that in Ubuntu you can use the GUI to shutdown the computer without a password, but if you use the poweroff command you will need to type in a password?

Well there is an easy fix. The /etc/sudoers file governs the use of the sudo command.
It can also be configured to allow specified commands, users and/or groups to not have to worry about a sudo password.

In Ubuntu, this file also sources the /etc/sudoers.d/ directory so the sudoers file doesn’t get too cluttered.

I created a new file called “powercmds” under this directory with the following contents:

# Allow users in the admin group to poweroff the machine without a password
%admin ALL = NOPASSWD: /sbin/shutdown, /sbin/poweroff, /sbin/halt, /sbin/reboot

Then updated its permissions with this command:
sudo chmod 0440 /etc/sudoers.d/powercmds

Now anyone in the admin group will not require a password to shutdown the machine.

This is very useful for scripting, such as if I want to download a large file and have the computer shutdown when its finished (so I can go to bed or something) this is now possible:
wget http://somesite.com/somefile.big 2> ~/Desktop/dl.log; sudo poweroff

Search and replace, vim and git

Search and replace, vim and git Continue reading

Using netrw instead of NERDTree for Vim

Published on December 28, 2016