无需 SSH 即可远程关闭/重启 Linux 机器?

发布于 2024-12-21 14:36:24 字数 1549 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

懒的傷心 2024-12-28 14:36:24

正如 jørgensen 所指出的,您可以使用 SYSRQ (http://en.wikipedia.org/wiki/Magic_SysRq_key< /a>),直接与内核对话的 API。

请注意,这些都是非常硬核的,可能会损害您的硬件。重启需要花费单个 UDP 数据包传输的时间。繁荣。我们只在实时无盘计算机上使用它。

1. xt_SYSRQ(iptables模块,内核)

xt_SYSRQ是xtables-addons-common提供的iptables模块之一: http://manpages.ubuntu.com/manpages/oneiric/man8/xtables-addons.8.html

时安装

#!/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

在 debian Shotgun 重新启动

#!/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 监听守护进程,用户态

)仅当您的砖机计算机能够处理 TCP 连接时,该解决方案才有效。

上安装

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

在 debian Shutgun 重新启动

我制作了一个脚本, https://gist.github.com/qolund/1470beaa1a63e034025d 但它只是端口 4094 上的 TCP 连接。
您需要发送密码和命令,

# 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
[..]

连接未正确关闭,因为“b”重新启动命令太快,计算机已经重新启动。

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.

游魂 2024-12-28 14:36:24

几个选项:

这个工具并不完全是用来关闭机器的(但他们可以做到),它们是配置管理框架来管理很多机器,它们可以处理配置更改、软件包安装和更新,并在一台机器、一组机器或整个网络中运行您想要的所有命令。

A few options:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文