LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 10-26-2018, 09:32 AM   #1
usernameatdomain
LQ Newbie
 
Registered: Oct 2018
Posts: 9

Rep: Reputation: Disabled
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.
 
Old 10-26-2018, 10:42 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
It looks like you allowed to execute "/sbin/shutdown -h now" as it is. Did you try if that works?
 
Old 10-26-2018, 10:46 AM   #3
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
As the user david, what is output of following commands:

Code:
id
sudo -l
 
Old 10-26-2018, 11:03 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
The hostname may be a problem.

If nothing else works, try it with a hammer:

Code:
%users ALL=(root:root) /bin/shutdown -h now, /bin/shutdown -h [0-9][0-9]\:[0-9][0-9]
 
1 members found this post helpful.
Old 10-26-2018, 11:57 AM   #5
usernameatdomain
LQ Newbie
 
Registered: Oct 2018
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
It looks like you allowed to execute "/sbin/shutdown -h now" as it is. Did you try if that works?
It says
Code:
shutdown: Need to be root
 
Old 10-26-2018, 12:07 PM   #6
usernameatdomain
LQ Newbie
 
Registered: Oct 2018
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dc.901 View Post
As the user david, what is output of following commands:

Code:
id
sudo -l
id
Code:
uid=500(david) gid=500(david) groups=500(david),100(users) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
sudo -l
Code:
Sorry, user david may not run sudo on centos6.
 
Old 10-26-2018, 12:19 PM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by usernameatdomain View Post
id
Code:
uid=500(david) gid=500(david) groups=500(david),100(users) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
sudo -l
Code:
Sorry, user david may not run sudo on centos6.
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?
 
Old 10-26-2018, 12:33 PM   #8
usernameatdomain
LQ Newbie
 
Registered: Oct 2018
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
The hostname may be a problem.

If nothing else works, try it with a hammer:

Code:
%users ALL=(root:root) /bin/shutdown -h now, /bin/shutdown -h [0-9][0-9]\:[0-9][0-9]
I solved the problem. The hostname was the problem. My hostname on my CentOS 6 virtual machine is centos6, so I changed
Code:
%users  localhost=/sbin/shutdown -h now
to
Code:
%users  centos6=/sbin/shutdown -h now
 
Old 10-26-2018, 01:14 PM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
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...
 
Old 10-26-2018, 03:08 PM   #10
usernameatdomain
LQ Newbie
 
Registered: Oct 2018
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rhel visudo Read-only file system elbek Linux - Newbie 3 03-03-2017 12:15 PM
Grant read-only access to users using visudo? BCC Linux - Newbie 3 04-10-2013 04:30 PM
visudo: How to let a user run only a certain program as root? Ryan Hoots Linux - Newbie 6 09-09-2011 09:20 AM
Locking out non-root users while the system is in maintenance nthillaiarasu Linux - Security 5 05-09-2008 11:06 AM
shut down won't shut system down taoweijia Linux - General 3 03-03-2004 06:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration