My goal is to use reboot as myusername without entering a password. How can I achieve this?

I have read Allowing a user to use sudo without a password and followed the suggestions but it still doesn't work for me. Here is my /etc/sudoers but it still asks for a password:

# This file MUST be edited with the 'visudo' command as root.
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
# See the man page for details on how to write a sudoers file.
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
myusername  ALL=NOPASSWD:/sbin/reboot

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

I then run

sudo reboot

and am asked for a password. How can I run reboot as a normal user without being asked for a password?

Here is sudo -l output :

Matching Defaults entries for myusername on this host:
    env_reset, mail_badpass,

User myusername may run the following commands on this host:
    (root) NOPASSWD: /sbin/reboot
    (ALL : ALL) ALL

I also tried with

myusername  ALL=NOPASSWD:/bin/ls

but sudo ls still asked for a password so this seems to be a general problem, not specific to reboot.

  • 1
    You should read at least the first few lines of the sudo man page in order to understand the lowest basics of the tool. And after having done that you search in the sudoers man page for NOPASSWD. Feb 27, 2014 at 0:40
  • I amde a couple of changes to your question, you had some of the lines left over from our chat conversation and the one you had left had extra spaces. Please check and make sure that the edited version is exactly the same as what you have. Also, please update your question with the output of sudo -l.
    – terdon
    Feb 27, 2014 at 4:10
  • sudo -l says you are allowed to run /sbin/reboot but you call sudo reboot. Get the difference? Feb 27, 2014 at 10:23
  • sudo /sbin/reboot still asks for [sudo] password and /sbin/reboot says reboot:must be superuser Feb 27, 2014 at 10:57
  • @HaukeLaging no I don't. The OP has clearly either added /sbin to their path or set up an alias as suggested in my answer. What do you think is happening when he runs reboot as opposed to /sbin/reboot? In any case, /sbin is in the sudo path as you can see so, again...
    – terdon
    Feb 27, 2014 at 13:52

1 Answer 1


First of all, do not, I repeat NOT, attempt to make your user have root privileges at all times, that is the mother of all security risks and is not only unnecessary but asking for trouble.

Anyway, if you want your user to be able to run a specific command, you need to add this line to sudoers (change terdon to your username of course):

terdon ALL=NOPASSWD:/sbin/reboot

You can then run it with sudo reboot without entering a password. You will always need to run it with sudo though, the best you can get is passwordless sudo for certain commands.

This is because of the way the system works. When you attempt to run, for example shutdown -r, as a normal user, you get this message:

$ shutdown -r
shutdown: you must be root to do that!

This has nothing to do with sudo, the command in question simply checks whether your userid is 1 (the super user) and if it is not, it won't let you run it. You could set up your system to have another user as userid 1 but that would simply change the username of root and would be a lot of trouble for no reason (and would not help you do what you are attempting anyway).

So, unless you are actually logged in as the user whose userid is 1, you will always have to use sudo to run privileged commands. The only workaround would be to create an alias (or a function, or a script) for reboot in your shells's configuration file (~/.bashrc for example):

alias reboot='sudo shutdown -r now'

That way, since you have already set shutdown to be passwordless in /etc/sudoers, you will be able to run

$ reboot

and get your desired result.

  • 1
    appreciate your answer but I added the terdon ALL=NOPASSWD:/sbin/reboot line to /etc/sudoers and rebooted the system. But if I sudo reboot, it still asks for password. Feb 27, 2014 at 1:28
  • @Level1Coder you did you use actual username and not mine right?
    – terdon
    Feb 27, 2014 at 1:30
  • correct, I replaced terdon with my own username Feb 27, 2014 at 1:31
  • @Level1Coder yes, it doesn't seem to work for reboot, sorry. I edited and changed to shutdown -r instead (which does the same thing). It works fine like that on my Debian.
    – terdon
    Feb 27, 2014 at 1:36
  • @Level1Coder scratch that, it works fine with reboot, I just checked. I'm guessing that you had saved the file but not exited visudo when you ran the command. Anyway, using shutdown -r is better since it is likelier to work on older machines.
    – terdon
    Feb 27, 2014 at 1:46

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