2

I'm following along the Ubuntu sudoers tutorial.

Here's my exact /etc/sudoers file (screenshot instead of code block because the formatting was getting messed up).

sudoers file

Notice the lines at the bottom which should give the deployer user poweroff and reboot capabilities. The sudoers file is syntactically fine and saves no problem.

I've ended my ssh session and logged in again.

$ whoami => deployer $ reboot => reboot: Need to be root

What could the problem be?

Some thoughts

  • I've tried rebooting (with sudo) and still there's no effect
  • My shell is ZSH
  • I predict I'm going to kicking myself when I get an answer.
4
  • Please use a code block instead of a screenshot. We now need to copy by hand in order to attempt to replicate your setup. There's no reason why you can't format this correctly, see here for help on how. Anyway, you still need sudo reboot, it just won't ask you for a password.
    – terdon
    May 17, 2014 at 0:06
  • I know, the screenshot is annoying. I don't understand what is wrong with the code block. I have a lot of experience using them on Stack Overflow but it wouldn't work this time. Anyway, your comment about still needing sudo is what I was looking for. If you put that in an answer I will accept. May 17, 2014 at 0:13
  • Sure, I actually had it written up already so just a quick copy paste :). I'm curious why you had trouble formatting though. I'm guessing it was the # that were being treated as headers. You need a blank line above code blocks for them to be treated as such.
    – terdon
    May 17, 2014 at 0:21
  • Exactly. The # was being treated as a header and (it looked like it was) forcing the block to be rendered as markdown, which led to massive text sizing. I wasn't aware of the blank line trick so thanks for that. May 17, 2014 at 0:25

1 Answer 1

3

The settings you are using will allow your user to run 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 reboot, as a normal user, you get this message:

$ reboot
reboot: must be superuser.

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 reboot'

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .