Do you know if it is possible to create a user in linux that can only do "reboot" command without sudo?

the reason is, i need to automate the rebooting of my production server(s) without having to logging into each one, and then has to do "sudo reboot" and putting in the password (which can be time consuming)

  • 7
    Why exactly do you need to reboot the production server(s) each day? – Andrew Jun 15 '11 at 23:37

This can be done quite simply using /usr/sbin/visudo to add the following lines:

User_Alias REBOOTUSERS = Lee, testuser

After adding those lines the user(s) specified by the User_Alias REBOOTUSERS will be able to enter:

$sudo reboot

And it will reboot the server without a password prompt!

  • 5
    For extra safety, you should not edit /etc/sudoers directly, but rather use /usr/sbin/visudo. This performs file locking and some sanity checks to make sure the config is valid before saving. – Alex Jun 15 '11 at 23:32

Just use the NOPASSWD option in your sudoers config for that user/command.

  • For security reasons I would make sure that this userid cannot be used to ssh into your servers. This will add a layer of protection. Also, I would disable the password (NOTE: not blank password), which will make it impossible to login with this account, only su to it, or run commands. – slashdot Jun 16 '11 at 0:25
  • 2
    Look into ssh public key authentication. Then you can disable the passwords for said users and still be able to ssh in. – ptman Jun 16 '11 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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