Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remotely shutdown/reboot Linux boxes without SSH? [closed]

I need to remotely shutdown and reboot Linux (Ubuntu) machines without logging into them (otherwise simple commands can do the job). The machines are just cheap PCs so there are no special power management hardware installed (though they can wake-on-lan). Is there some sort of "power management server" software that I can install on those boxes, which listens to remote requests for reboot/shutdown and acts accordingly? Of course it would be nice if it requires some authentication (password) in order to respond to the requests.

like image 657
jasxun Avatar asked Dec 16 '11 00:12

jasxun


2 Answers

As pointed out by jørgensen, you can use SYSRQ (http://en.wikipedia.org/wiki/Magic_SysRq_key), an API directly talking to the kernel.

Beware, these are quite hardcore and may harm your hardware. It takes the time of a single UDP packet transfer to reboot. Boom. We only use it on live diskless computers.

1. xt_SYSRQ (iptables modules, kernel)

There is xt_SYSRQ, one of the iptables modules provided by xtables-addons-common : http://manpages.ubuntu.com/manpages/oneiric/man8/xtables-addons.8.html

Installing on debian

#!/bin/bash
apt-get install -qq xtables-addons-common iptables
echo -n "yolo" >/sys/module/xt_SYSRQ/parameters/password
iptables -A INPUT -p udp --dport 9 -j SYSRQ

Shotgun reboot

#!/bin/bash
sysrq_key="sub"  # the SysRq key(s), Sync, Unmount, reBoot
password="yolo"
seqno="$(date +%s)"
salt="$(dd bs=12 count=1 if=/dev/urandom 2>/dev/null | openssl enc -base64)"
ipaddr="$1"
req="$sysrq_key,$seqno,$salt"
req="$req,$(echo -n "$req,$ipaddr,$password" | sha1sum | cut -c1-40)"
echo "$req" | socat stdin udp-sendto:$ipaddr:9

2. sysrqd (tcp 4094 listening daemon, userland)

This solution works only if your bricked computer is able to handle TCP connections.

Installing on debian

#!/bin/bash
apt-get install -qq sysrqd
echo "yolo" > /etc/sysrqd.secret
service sysrqd restart

Shutgun reboot

I made a script, https://gist.github.com/qolund/1470beaa1a63e034025d but its just a TCP connexion on port 4094. You need to send the password and the commands,

# telnet 172.16.42.180 4094
Trying 172.16.42.180...
Connected to 172.16.42.180.
Escape character is '^]'.
sysrqd password: nope
Go away!
Connection closed by foreign host.
# telnet 172.16.42.180 4094
Trying 172.16.42.180...
Connected to 172.16.42.180.
Escape character is '^]'.
sysrqd password: yolo
sysrq> sub
[..]

The connection isn't properly closed, because the 'b' reboot command is too fast, the computer is already rebooting.

like image 146
Nope Avatar answered Sep 20 '22 12:09

Nope


A few options:

  • puppet
  • chef
  • cfengine

This tools are not exactly to shutdown machines (but they can do it), they are configuration management frameworks to administer a lots of machines, they can handle configuration changes, package installs and updates, and run all the commands you want, in one machine, in a set of machines, or in the whole network.

like image 30
Pablo Castellazzi Avatar answered Sep 18 '22 12:09

Pablo Castellazzi