How do I get a local(client) reboot (init 6) when a ssh connection is closed?
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
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.
Distribution: I have multiple Distos available, but I mostly use Ubuntu.
Posts: 47
Rep:
How do I get a local(client) reboot (init 6) when a ssh connection is closed?
How do I get a local client to reboot(init 6) when a ssh connection is closed? I think I must modify the local ssh_config or sshd_config.
What I am looking for, is a way to force a local client to reboot(init 6) when a ssh session ends. Perhaps there is a better way, script, or cron to accomplish this.
Alright, here's the bit. I have rewritten a Knoppix LiveCD to boot into only an "init 1" environment(init 6 and init 0 are also available). When a client, using this LiveCD, secure shells(ssh) onto a remote server, and then exits "this ssh session", I wish to have the LiveCD reboot (init 6).
Thanks in advance! ...... I know this is a hard one for the community to solve.... A challenge.
I know this is a hard one for the community to solve.... A challenge.
If you boot into runlevel 1, and have no option to go to 3-5, then no, not really. No network, no SSH. There you have it ;-p All fun aside you could move the 'ssh' binary to another location and replace it with a wrapper shellscript that executes the commandline and then does a 'sudo /sbin/shutdown -r' the box. Can't imagine why you would want to make it reboot though. If you don't script exceptions or a choice then reboot will happen on *every* ssh session exit, even where it failed to connect to a system due to whatever reasons.
Distribution: I have multiple Distos available, but I mostly use Ubuntu.
Posts: 47
Original Poster
Rep:
How do I get a local(client) reboot (init 6) when a ssh connection is closed?
Thank you for the reply! It is late here and I am digesting your thoughts. As to your:
"Can't imagine why you would want to make it reboot though. If you don't script exceptions or a choice then reboot will happen on *every* ssh session exit, even where it failed to connect to a system due to whatever reasons."
EXACTLY! It keeps my students from highlighting their work, "right clicking", exiting their ssh session, logging onto a friends home directory through a ssh session, vi a file, PASTE.......... copy work from one to another.
NOTE: I teach programming in public school. "Our" environment is use of my this, my Knoppix LiveCD rewrite. They ssh onto a Linux server and work there ....... Got to stay ahead on these students!!!
Isn't that a bit crude? Not to be idealistic about this, but if you expect or are faced with a major outbreak of plagiarism then wouldn't your efforts be better directed looking into *why* it's ocurring in the first place? I mean if you know they're good students but facing time constraints then maybe that's something to adjust? Else if they just don't give a rodent's ass wouldn't it be easier to look for common phrasing and such and allow for way more severe punishment for offenders?
Firstly, if you edit /etc/inittab to remove the extra "getty" lines, you can prevent the students from switching to another terminal.
To automatically have them ssh to the central server on login, and have it reboot when that ssh connection closes, try appending this to the existing /home/knoppix/.bash_profile :
echo "Your Server Login Name: "
read studentusername
echo "What Server IP Address: "
read remoteserver
ssh -l $studentusername $remoteserver
echo "You are done"
sudo shutdown -r now
There are also some tricks you can play by replacing the shell specified in /etc/password with a "wrapper" script. A good example is the cvsssh.pl script used for that purpose in gforge, you can find it on the web.
That should be enough to make it require more than a spur-of-the-moment impulse to cheat . . . then you can focus on teaching your course material instead of teaching what their parents should have taught them at home
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.