1
$ which reboot

/usr/bin/reboot

$ sudo reboot

Sorry, user myusername is not allowed to execute '/sbin/reboot' as root

What am I missing here?

Stephane Rolland
  • 449
  • 2
  • 7
  • 14
John Smith Optional
  • 502
  • 2
  • 9
  • 18

3 Answers3

0

when you run a command as root, files inside the sbin folder have a higher priority than the other folders in your path. Thats why sudo chooses /sbin/reboot. You have to use /sbin/reboot in your sudoers file, or you have to explicitly call sudo /usr/bin/reboot

Pascal Schmiel
  • 1,738
  • 12
  • 17
0

What this is telling you is that your sudo rights do not include the ability to use the reboot application. The PATH is not being modified; it can find reboot just fine.

cat /etc/sudoers, and modify with visudo as necessary.

gWaldo
  • 11,957
  • 8
  • 42
  • 69
  • I had added /usr/bin/reboot with visudo. My user should be able to do a reboot with sudo according to my sudoers file. But instead, I'm asked my password and then I get the message decribed in the OP. – John Smith Optional May 15 '13 at 13:45
  • The only CentOS box I have is 5.9 (mostly Ubuntu here), but it looks like /usr/bin/reboot is a link to another application. – gWaldo May 15 '13 at 13:56
  • If you can use `visudo`, why don't you give yourself permissions to `/sbin/reboot`? – gWaldo May 15 '13 at 13:57
  • I allowed /sbin/reboot, as well as /sbin/shutdown in visudo. When I run `$ sudo /sbin/reboot` I get this message: `reboot: Unable to execute shutdown: Permission denied` – John Smith Optional May 15 '13 at 14:06
  • This last message seems to be caused by the NOEXEC option in my sudoers file. Apparently reboot is calling /bin/bash. I wonder why. – John Smith Optional May 15 '13 at 14:15
-1

I think it has something to do with this question:

https://stackoverflow.com/questions/257616/sudo-changes-path-why

So sudo changes the path, but passes it unchanged to the command. So it uses /sbin/reboot for the reboot command, but passes the usual path to the which command (which consequently finds sudo in /usr/bin/reboot).

Boelensman1
  • 118
  • 4
  • I think you're right. The secure_path option in my sudoers file is the following: `Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin`. Your link helped me figure out what was happening. – John Smith Optional May 16 '13 at 09:08