[RESOLVED] How to allow non-root user to shutdown

General support questions
stevemowbray
Posts: 477
Joined: 2012/06/26 14:20:47

Re: How to allow non-root user to shutdown

Post by stevemowbray » 2014/10/16 09:18:40

"sudo shutdown -h now" remotely returns error:

Code: Select all

sudo: sorry, you must have a tty to run sudo
Add the "-t" option to your plink command line to allocate a pty. I have just verified that this works.

NickC
Posts: 185
Joined: 2012/01/20 16:13:41

Re: How to allow non-root user to shutdown

Post by NickC » 2014/10/16 10:39:52

TrevorH wrote:That last one should work, as should the one before. It wants the password for the user in question not the root password.

Code: Select all

[trevor@xps13 plugins]$ /sbin/shutdown -r now
==== AUTHENTICATING FOR org.freedesktop.login1.reboot ===
Authentication is required for rebooting the system.
Authenticating as: trevor
Password: 
==== AUTHENTICATION COMPLETE ===
[trevor@xps13 plugins]$ Connection to xps13 closed by remote host.
Connection to xps13 closed.
[/cpde][/quote]
Yep, they do.  Sorry Trevor, I didn't make it very clear those two work from SSH prompt but clearly won't work from a batch file due to the extra inputs required.

User avatar
TrevorH
Forum Moderator
Posts: 26590
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: How to allow non-root user to shutdown

Post by TrevorH » 2014/10/16 12:26:46

How does that fit with "We will need to have it send the users password for security"? That's exactly what it does.
CentOS 5 died in March 2017 - migrate NOW!
CentOS 6 goes EOL sooner rather than later, get upgrading!
Full time Geek, part time moderator. Use the FAQ Luke

NickC
Posts: 185
Joined: 2012/01/20 16:13:41

Re: How to allow non-root user to shutdown

Post by NickC » 2014/10/16 13:19:41

TrevorH wrote:How does that fit with "We will need to have it send the users password for security"? That's exactly what it does.
ok to send the remoteshutdown users password but would prefer not to have the root password laying around in batch files.

NickC
Posts: 185
Joined: 2012/01/20 16:13:41

Re: How to allow non-root user to shutdown

Post by NickC » 2014/10/16 15:41:15

Simple answer now found:

Code: Select all

chmod +s /sbin/shutdown
then remote batch file works fine without any of the sudoers mess

Code: Select all

plink.exe -ssh -pw <password> remoteshutdown@n.n.n.n "/sbin/shutdown -h now"

User avatar
TrevorH
Forum Moderator
Posts: 26590
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: [RESOLVED] How to allow non-root user to shutdown

Post by TrevorH » 2014/10/16 16:29:45

ok to send the remoteshutdown users password but would prefer not to have the root password laying around in batch files.
It isn't asking for the root password, it's asking for the user's password.
CentOS 5 died in March 2017 - migrate NOW!
CentOS 6 goes EOL sooner rather than later, get upgrading!
Full time Geek, part time moderator. Use the FAQ Luke

NickC
Posts: 185
Joined: 2012/01/20 16:13:41

Re: [RESOLVED] How to allow non-root user to shutdown

Post by NickC » 2014/10/16 20:26:58

TrevorH wrote: It isn't asking for the root password, it's asking for the user's password.
Yes but the wrong user, not the one we are trying to use.

User avatar
TrevorH
Forum Moderator
Posts: 26590
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: [RESOLVED] How to allow non-root user to shutdown

Post by TrevorH » 2014/10/17 08:06:58

What? It's asking for the password for the user you are connecting as. If you connect as the wrong user then it will ask for the password for that user. Solution: connect as the user you want to use!
CentOS 5 died in March 2017 - migrate NOW!
CentOS 6 goes EOL sooner rather than later, get upgrading!
Full time Geek, part time moderator. Use the FAQ Luke

NickC
Posts: 185
Joined: 2012/01/20 16:13:41

Re: [RESOLVED] How to allow non-root user to shutdown

Post by NickC » 2014/10/17 12:10:49

TrevorH wrote:What? It's asking for the password for the user you are connecting as. If you connect as the wrong user then it will ask for the password for that user. Solution: connect as the user you want to use!
but it was asking for the password from the wrong user, let me explain:

Code: Select all

plink.exe -ssh -pw <password> remoteshutdown@n.n.n.n "/sbin/shutdown -h now"
turns out it wasn't asking for the password for the 'remoteshutdown' user rather it wanted the password for the 'nicktest' user!

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: [RESOLVED] How to allow non-root user to shutdown

Post by gerald_clark » 2014/10/17 12:19:49

Do 'remoteshutdown' and 'nicktest' have the same user number in /etc/passwd?

Post Reply

Return to “CentOS 7 - General Support”