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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
WordPress大学
WordPress大学
Recent Announcements
Recent Announcements
G
Google Developers Blog
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
C
Check Point Blog
J
Java Code Geeks
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
V
Visual Studio Blog
人人都是产品经理
人人都是产品经理
量子位
A
About on SuperTechFans
D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

Solene'%

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 la...
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.