LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-12-2014, 04:56 PM   #1
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 297

Rep: Reputation: Disabled
How to allow non-root user to shutdown


Can anyone tell me how I can allow a non-root user to use the shutdown command in CentOS 7?

I am currently shutting down the machine remotely which is working fine as 'root' but I would prefer to create a new user say 'remoteshutdown' to use for this instead of root.

Problem is I cannot seem to find out how to allow a non root user permission to shutdown.

Thanks,
 
Old 10-12-2014, 05:03 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,289

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
run visudo as root.

Last edited by schneidz; 10-12-2014 at 05:13 PM.
 
Old 10-13-2014, 08:32 AM   #3
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 297

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
run visudo as root.
Yep, looked at that but I understood that only affects commands run through sudo. I want to shutdown machine remotely and do not want to have to include root password in batch/script file.
 
Old 10-13-2014, 08:44 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,289

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
Code:
[schneidz@mom ~]$ sudo visudo
...
## Allows people in group wheel to run all commands
#%wheel ALL=(ALL)       ALL

## Same thing without a password
 %wheel ALL=(ALL)       NOPASSWD: ALL

## Allows members of the users group to shutdown this system
# %users  localhost=/sbin/shutdown -h now
...

Last edited by schneidz; 10-13-2014 at 08:48 AM.
 
Old 10-13-2014, 04:54 PM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,502

Rep: Reputation: 2617Reputation: 2617Reputation: 2617Reputation: 2617Reputation: 2617Reputation: 2617Reputation: 2617Reputation: 2617Reputation: 2617Reputation: 2617Reputation: 2617
that should already be the default setup
to allow users to run
Code:
shutdown -h
now for a remote ( ssh /vpn ) power off or reboot
THAT SHOULD be only root
 
Old 10-13-2014, 05:34 PM   #6
timl
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Fedora,CentOS
Posts: 699

Rep: Reputation: 151Reputation: 151
Just a clarification

Quote:
I want to shutdown machine remotely and do not want to have to include root password in batch/script file.
Once a user has sudo rights that user can achieve root privileges by issuing the sudo command. When that user issues the sudo command they type in their password and not the root password. So, after typing:

Quote:
sudo cat /var/log/yum.log
that user will be asked for their password not the root password
 
Old 10-14-2014, 07:56 AM   #7
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 297

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
Code:
[schneidz@mom ~]$ sudo visudo
...
## Allows people in group wheel to run all commands
#%wheel ALL=(ALL)       ALL

## Same thing without a password
 %wheel ALL=(ALL)       NOPASSWD: ALL

## Allows members of the users group to shutdown this system
# %users  localhost=/sbin/shutdown -h now
...
Tried that but now get error:
Code:
Could not chdir to home directory wheel: No such file or directory
bash: shutdown: command not found
 
Old 10-14-2014, 08:03 AM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,085

Rep: Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957
what have you tried? It has no meaning just drop an error message:
/sbin/shutdown -h now is configured in that configfile, that should be entered/executed.
shutdown normally not found, because it is in /sbin and /sbin is not in PATH (for general users).
 
Old 10-14-2014, 08:39 AM   #9
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,289

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
copy-pasta the output of:
Code:
[schneidz@mom ~]$ sudo cat /etc/sudoers
so someone has a starting point to debug. also what is the exact command that resulted in the above error message ?
 
Old 10-14-2014, 08:44 AM   #10
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 297

Original Poster
Rep: Reputation: Disabled
visudo:
Code:
...
## Allows people in group wheel to run all commands
#%wheel ALL=(ALL)       ALL

## Same thing without a password
%wheel ALL=(ALL)       NOPASSWD: ALL

## Allows members of the users group to shutdown this system
%users  localhost=/sbin/shutdown -h now
%wheel  localhost=/sbin/shutdown -h now
...
User remoteshutdown added to both users & wheel groups.

Running "shutdown -h now" remotely returns error:
Code:
Could not chdir to home directory wheel: No such file or directory
bash: shutdown: command not found
Running "sudo shutdown -h now" remotely returns error:
Code:
Could not chdir to home directory wheel: No such file or directory
sudo: sorry, you must have a tty to run sudo

Last edited by Nick_C; 10-14-2014 at 08:48 AM.
 
Old 10-14-2014, 08:57 AM   #11
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,289

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
just for shiggles can you try running it like:
Code:
sudo /sbin/shutdown -h now
# and
sudo /usr/sbin/shutdown -h now
also, maybe there isnt a a homedir for that user. does
Code:
cat /etc/passwd | grep remoteshutdown
provide anything useful ?

Last edited by schneidz; 10-14-2014 at 08:59 AM.
 
Old 10-14-2014, 09:47 AM   #12
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 297

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
Code:
sudo /sbin/shutdown -h now
# and
sudo /usr/sbin/shutdown -h now
both fail with:
Code:
Could not chdir to home directory wheel: No such file or directory
sudo: sorry, you must have a tty to run sudo
Quote:
Originally Posted by schneidz View Post
Code:
cat /etc/passwd | grep remoteshutdown
returns:
Code:
remoteshutdown:x:1002:1003::wheel:/bin/bash
 
Old 10-14-2014, 10:01 AM   #13
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,289

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
the users home-directory looks weird (wheel) ?
 
Old 10-14-2014, 10:21 AM   #14
Nick_C
Member
 
Registered: Jan 2012
Location: London, England, UK
Distribution: CentOS 6, CentOS 7
Posts: 297

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
the users home-directory looks weird (wheel) ?
Don't know what went wrong there, user now deleted and recreated.
cat /etc/passwd | grep remoteshutdown returns
Code:
remoteshutdown:x:1002:1005::/home/remoteshutdown:/bin/bash
 
Old 10-14-2014, 10:27 AM   #15
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,289

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
i think you are good to retry... its probably gonnna' ask for a passwd. i think you need to put that NOPASSWD directive somewhere on that line in visudo... i am not a visudo expert so you will need to experiment a little.

also i think there is a way to disable the need of a tty for using sudo with ssh but makes things a little less secure.
 
  


Reply

Tags
centos, shutdown


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] mount, shutdown as non-root user darksaurian Slackware 7 06-06-2010 11:25 PM
shutdown with a not root user krusty_lab AIX 2 10-18-2005 06:07 PM
Root User freezes on logout or shutdown grizzlyaka Linux - Laptop and Netbook 2 04-27-2005 08:20 AM
Can't shutdown as any user but root? JustinCoyan Slackware 4 06-10-2004 01:05 PM
how to allow a not root user to shutdown ethanchic Linux - General 9 06-18-2002 05:08 AM

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

All times are GMT -5. The time now is 08:39 AM.

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