惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
罗磊的独立博客
SecWiki News
SecWiki News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
IT之家
IT之家
博客园 - 聂微东
T
The Exploit Database - CXSecurity.com
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Vercel News
Vercel News
G
GRAHAM CLULEY
D
DataBreaches.Net
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
博客园_首页
雷峰网
雷峰网
T
Tenable Blog
Spread Privacy
Spread Privacy
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
V
Visual Studio Blog
J
Java Code Geeks
博客园 - Franky
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
T
Threatpost
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
U
Unit 42
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
K
Kaspersky official blog
有赞技术团队
有赞技术团队
B
Blog
腾讯CDC

Solene'%

Solene'% : Software to keep photos organized Solene'% : Make your own container base images from trusted sources Solene'% : File transfer made easier with Tailscale Solene'% : Comparison of cloud storage encryption software Solene'% : Revert fish shell deleting shortcuts behavior Solene'% : Declaratively manage containers on Linux Solene'% : Hardware review: ergonomic mouse Logitech Lift Solene'% : URL filtering HTTP(S) proxy on Qubes OS Solene'% : Introduction to Qubes OS when you do not know what it is
Solene'% : How to trigger a command on a running Linux laptop when disconnected from power
2025-05-31 · via Solene'%

Written by Solène, on 31 May 2025.
Tags: #security #linux

Table of contents

  • 1. Introduction
  • 2. Setup
  • 3. Testing
  • 4. Script ideas
  • 5. Conclusion

1. Introduction §

After thinking about BusKill product that triggers a command once the USB cord disconnects, I have been thinking at a simple alternative.

BusKill official project website

When using a laptop connected to power most of the time, you may want it to power off once it gets disconnected, this can be really useful if you use it in a public area like a bar or a train. The idea is to protect the laptop if it gets stolen while in use and unlocked.

Here is how to proceed on Linux, using a trigger on an udev rule looking for a change in the power_supply subsystem.

For OpenBSD users, it is possible to use apmd as I explained in this article:

=> Rarely known OpenBSD features: apmd daemon hooks

In the example, the script will just power off the machine, it is up to you to do whatever you want like destroy the LUKS master key or trigger the coffee machine :D

2. Setup §

Create a file /etc/udev/rules.d/disconnect.rules, you can name it how you want as long as it ends with .rules:

SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", ENV{POWER_SUPPLY_TYPE}=="Mains", RUN+="/usr/local/bin/power_supply_off"

Create a file /usr/local/bin/power_supply_off that will be executed when you unplug the laptop:

#!/bin/sh
echo "Going off because power supply got disconnected" | systemd-cat
systemctl poweroff

This simple script will add an entry in journald before triggering the system shutdown.

Mark this script executable with:

chmod +x /usr/local/bin/power_supply_off

Reload udev rules using the following commands:

udevadm control --reload-rules
udevadm trigger

3. Testing §

If you unplug your laptop power, it should power off, you should find an entry in the logs.

If nothing happens, looks at systemd logs to see if something is wrong in udev, like a syntax error in the file you created or an incorrect path for the script.

4. Script ideas §

Depending on your needs, here is a list of actions the script could do, from gentle to hardcore:

  • Lock user sessions
  • Hibernate
  • Proper shutdown
  • Instant power off (through sysrq)
  • Destroy LUKS master key to make LUKS volume unrecoverable + Instant power off

5. Conclusion §

While BusKill is an effective / unusual product that is certainly useful for a niche, protecting a running laptop against thieves is an extra layer when being outside.

Obviously, this use case works only when the laptop is connected to power.