LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-16-2017, 08:16 PM   #1
Waiyan Lynn
LQ Newbie
 
Registered: Nov 2017
Posts: 8

Rep: Reputation: Disabled
Auto Shutdown Script in centos


hi,

How can I make my centOS6 automatically shut down after the specific local user log in?
 
Old 11-16-2017, 11:05 PM   #2
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 759

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Welcome to LQ. web-research the 'shell' field, at the end of /etc/passwd entries.
Or like .bashrc login scripts.

Tell us a bit about your computers, Linux experience/interests/goals, Google knowledge.
 
Old 11-17-2017, 12:03 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,675
Blog Entries: 3

Rep: Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907
Yes, more information is needed. How is that user going to log in? At the console or via SSH?
 
Old 11-18-2017, 03:41 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 17,426
Blog Entries: 10

Rep: Reputation: 5237Reputation: 5237Reputation: 5237Reputation: 5237Reputation: 5237Reputation: 5237Reputation: 5237Reputation: 5237Reputation: 5237Reputation: 5237Reputation: 5237
Quote:
Originally Posted by !!! View Post
Welcome to LQ. web-research the 'shell' field, at the end of /etc/passwd entries.
that sounds like a genius idea: shell=/bin/poweroff or sth like that.
at least a literal answer to op's question.
however i wonder what the bigger picture here is; it seems weird to shut down a machine after logging in?
 
Old 11-19-2017, 01:14 AM   #5
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 759

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Thanks for the +1

I vaguely remember some site where there was a 'shutdown' user account,
which shutdown the computer when someone (with pwd) logged into that acnt.
(The person may have had NO other login/access/reason to use computer;
just the lights-turner-outer)

Oh, p.s., web-search: linux "shutdown account" find a lot:
https://askubuntu.com/questions/1374...utdown-account

http://forums.justlinux.com/showthre...count-question
Hey, WHO deleted the shutdown user from Linux's /etc/passwd??? LP?
(I'm glad I doNOT have an /etc/passwd file in my distro-of-choice)


OP never came back. ('real'? That's why my last sentence in #2)

Last edited by !!!; 11-19-2017 at 01:26 AM.
 
Old 11-20-2017, 04:30 AM   #6
Waiyan Lynn
LQ Newbie
 
Registered: Nov 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Yes, more information is needed. How is that user going to log in? At the console or via SSH?
I want to use that user account via ssh. My centos is running over hyper-v. I want to shut down the system whenever I log in with that username and password automatically. I've tried like this https://askubuntu.com/questions/1374...utdown-account but still can't access to that shutdown account and saying Access denied.
 
Old 11-20-2017, 04:44 AM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,675
Blog Entries: 3

Rep: Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907
Quote:
Originally Posted by Waiyan Lynn View Post
I want to use that user account via ssh. My centos is running over hyper-v. I want to shut down the system whenever I log in with that username and password automatically. I've tried like this https://askubuntu.com/questions/1374...utdown-account but still can't access to that shutdown account and saying Access denied.
1. Can you log in with that user using SSH keys?

2. Once logged in can you run the script using sudo and then the machine shuts down?

If not work on those two steps. If so, then prepend the key found in that account's ~/.ssh/authorized_keys file with command="/usr/bin/sudo /path/to/script", using the right paths and script name of course.
 
1 members found this post helpful.
Old 11-20-2017, 08:30 PM   #8
Waiyan Lynn
LQ Newbie
 
Registered: Nov 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
1. Can you log in with that user using SSH keys?

2. Once logged in can you run the script using sudo and then the machine shuts down?

If not work on those two steps. If so, then prepend the key found in that account's ~/.ssh/authorized_keys file with command="/usr/bin/sudo /path/to/script", using the right paths and script name of course.
Sry for the wrong link. I've tried this https://www.cyberciti.biz/tips/shutd...ux-server.html
and it is perfectly shut down when I log in from the console but can't log in from the ssh and keep saying Access Denied. Thank you so much for your replies.

Last edited by Waiyan Lynn; 11-20-2017 at 08:31 PM.
 
Old 11-20-2017, 09:27 PM   #9
giis
Member
 
Registered: Nov 2013
Location: Third Rock from Moon
Distribution: RPM/DEB based and LFS
Posts: 73

Rep: Reputation: Disabled
You want to disable the account completely ? Something usermod -s /sbin/nologin username will prevent access. Any specific reason you want to him login and the shutdown vm?
 
Old 11-20-2017, 09:32 PM   #10
Waiyan Lynn
LQ Newbie
 
Registered: Nov 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by giis View Post
You want to disable the account completely ? Something usermod -s /sbin/nologin username will prevent access. Any specific reason you want to him login and the shutdown vm?
I don't want to disable that account. I want some users to shut down the system by logging into that account without giving them any root permissions

Last edited by Waiyan Lynn; 11-20-2017 at 09:35 PM.
 
Old 11-20-2017, 10:07 PM   #11
giis
Member
 
Registered: Nov 2013
Location: Third Rock from Moon
Distribution: RPM/DEB based and LFS
Posts: 73

Rep: Reputation: Disabled
Quote:
Originally Posted by Waiyan Lynn View Post
I don't want to disable that account. I want some users to shut down the system by logging into that account without giving them any root permissions
Okay, Simply adding shutdown command into "~/.bash_profile" will help your case?
 
Old 11-21-2017, 02:02 AM   #12
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,675
Blog Entries: 3

Rep: Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907Reputation: 2907
Quote:
Originally Posted by giis View Post
Okay, Simply adding shutdown command into "~/.bash_profile" will help your case?
Those settings quite easily circumvented.

Weiyan, about getting the key-based login, if you can log into the server with the account shutdown using the password, then on the client:

Code:
ssh-keygen -t ed25519 -f ~/.ssh/shutdown-server.ed25519 -C 'waiyan from client'

ssh-copy-id -i ~/.ssh/shutdown-server.ed25519 shutdown@server.example.com
Then test the key

Code:
ssh -i ~/.ssh/shutdown-server.ed25519 shutdown@server.example.com
If that works, then follow the sudoers modification in your guide. Though I would say to allow more options so you could have another key reboot or do a timed shutdown. So on the server add this to /etc/sudoers:

Code:
shutdown ALL=(root:root) NOPASSWD: /sbin/shutdown
Then you should be able to log in with the key and manually run things like sudo /sbin/shutdown -k +5 'yer done get out'

Then if that works, on the shutdown account on the server modify the key in ~/.ssh/authorized_keys
so that it automatically runs shutdown

before:

Code:
ssh-ed25519 AAAAC3Nza...00sbl/Q waiyan from client
after:

Code:
command="/sbin/shutdown -h +1 'yer done. get out.'" ssh-ed25519 AAAAC3Nza...00sbl/Q waiyan from client
Then if that works you can use a Match clause in sshd_config to eliminate the password login for that user.
 
1 members found this post helpful.
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an auto-deployment script for centos sysmicuser Linux - Newbie 3 06-26-2016 04:59 PM
Puppy linux slacko 5.7 daily auto shutdown script illa1980 Linux - Newbie 3 11-29-2014 04:17 PM
run auto script when interface comes up or down on centos bobo0110 Linux - Server 1 03-15-2011 04:31 AM
run auto script when interface comes up or down on centos bobo0110 Linux - Newbie 2 03-15-2011 02:15 AM
Cannot run auto shutdown script for oracle database inaki Linux - Newbie 1 03-18-2010 02:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:41 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