To run the command
reboot one needs to be super user. Is there anyway I can run this as a normal user? I just don't want to
sudo and enter my password every time I reboot or power off.
/etc/sudoers so that every user that is in the admin group can execute the following commands without being ask for a password.
You just need to add the following lines to
## Admin user group is allowed to execute halt and reboot
%admin ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff
and add yourself to the admin group.
If you want only one user to be able to do this just remove the
%admin and replace it with
username like this
## user is allowed to execute halt and reboot
stormvirux ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff
You can find out more about
man sudoers or the online manpage
You can also create a new file under
/etc/sudoers.d name it as you wish(I named it
'shutdown'), and put the following lines inside:
# Allows me to shutdown the system without a password
yourUserName ALL = NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff
Just change "yourUserName" for YOUR User Name, and add or remove commands to use, personally I use it only for
shutdown. One of the main difference of creating a particular file under
sudoers.d is that this file will survive System Upgrades
sudo echo $USER >> /etc/shutdown.allow
Then you're able to use one of this commands:
shutdown -ah now // halt
shutdown -ar now // reboot
According man shutdown there is -a option for non-root usage:
shutdownis called with the -a argument (add this to the invocation of shutdown in /etc/inittab), it checks to see if the file /etc/shutdown.allow is present. It then compares the login names in that file with the list of people that are logged in on a virtual console ...
It works in Debian Linux. And there is limit for 32 user names in
You can also achieve this by trick with setuid. I don't know if it will work on all systems, because they sometimes ignore setuid/setgid bit.
You can specify a group of users who can perform change of system state in my case it was
adm. Then add appropriate users to this group.
gpasswd -a $USER adm
chmod 4550 /usr/bin/reboot
ls -l outpus should look like this:
-r-sr-x--- 1 root adm 18928 Mar 13 2015 /usr/bin/reboot
Afterwards you can just type:
Another way to achieve not only boot privileges but access to all systemctl services for a specific user or group in a Debian system is doing this:
sudo chown root:myuserorgroup /bin/systemctl
sudo chmod 4755 /bin/systemctl
Because all boot scripts
/sbin/reboot are links to
/bin/systemctl, changind its permissions and ownership grants the necessary privilege to execute it as root user.
Be aware that the user will be able to execute all systemctl operations. This may sound as a security threat, but it is a simple general solution to embbeded systems where your default user must not only have the access rights to shudown but also to work with all the other system services related to
Here's what I have done when I needed this. It may not work if the shutdown needs to happen right away, but it has the advantage that it needs neither extra privilege nor
- Create and maintain a directory somewhere (maybe under
/var/tmp) which is normally empty but fully accessible by you
- When you need to force a shutdown, just touch an empty file into existence in that directory
- A root cron job runs every minute and checks if that file exists
- If so, the cron job removes the file and shuts down.
I did this in the context of shutting down a Raspberry Pi when the UPS hat  on it stays on battery power for too long. I wanted to run the monitoring script as a normal user.
Warning: do not look at the code on that webpage, it is very bad for your eyes :-P