[SOLVED] Using visudo to allow non-root users to shut down the system
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Using visudo to allow non-root users to shut down the system
I am running CentOS 6 in a virtual machine and I want to know if it is possible to use visudo to allow non-root users to use the poweroff, shutdown, and reboot commands.
I think the relevant line from /etc/sudoers is
Code:
%users localhost=/sbin/shutdown -h now
I want a user named david to be able to shut down and reboot the system, so I entered usermod -aG users david as root. The groups david command shows
Code:
david : david users
When I enter sudo shutdown -h now as david it says that david is not allowed to run sudo. Eventually I would like to allow the users group to use the poweroff and reboot commands in /etc/sudoers without a password, but I thought I would first try the default configuration in /etc/sudoers that allows members of the users group to use sudo shutdown -h now.
I became curious about this because I also run CentOS 7 in a virtual machine and I can run poweroff, shutdown, and reboot as a non-root user without modifying /etc/sudoers. I do not know how much this has to do with systemd because I also have a virtual machine with Debian 9 and I have the same results with visudo as CentOS 6.
Without seeing your sudoer's file, I'd guess the problem is in there, based on your posts. A good number of 'default' sudoers files will have sudo restricted to members of the "wheel" group...is that the case on your system?
It is really great you could solve it.
Just one comment: localhost is always the current (local) host where you logged in, so probably you made some other changes too...
It is really great you could solve it.
Just one comment: localhost is always the current (local) host where you logged in, so probably you made some other changes too...
I think the only relevant change I made was making my hostname centos6 instead using the default hostname called localhost. If I used localhost as my hostname on my CentOS 6 virtual machine I would not have had this problem, but this was an interesting learning experience. I thought localhost in the context of /etc/sudoers meant the 127.0.0.1 loopback address, but it refers to the literal hostname "localhost". I did a Google search for "/etc/sudoers hostname" (without quotes) and I found a thread on the Ubuntu Forums that explained how to configure /etc/sudoers.
Last edited by usernameatdomain; 10-26-2018 at 03:09 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.