{"id":21887074,"url":"https://github.com/boredsquirrel/security-shutdown","last_synced_at":"2025-08-24T14:24:41.229Z","repository":{"id":231306086,"uuid":"624175429","full_name":"boredsquirrel/Security-shutdown","owner":"boredsquirrel","description":"Two ways to automatically shutdown your Linux PC/Laptop if there is has no power supply attached.","archived":false,"fork":false,"pushed_at":"2023-04-05T23:41:46.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T20:22:50.729Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/boredsquirrel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-04-05T22:51:46.000Z","updated_at":"2023-04-05T22:51:46.000Z","dependencies_parsed_at":"2024-04-03T12:37:37.148Z","dependency_job_id":null,"html_url":"https://github.com/boredsquirrel/Security-shutdown","commit_stats":null,"previous_names":["boredsquirrel/security-shutdown"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boredsquirrel%2FSecurity-shutdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boredsquirrel%2FSecurity-shutdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boredsquirrel%2FSecurity-shutdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boredsquirrel%2FSecurity-shutdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boredsquirrel","download_url":"https://codeload.github.com/boredsquirrel/Security-shutdown/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244894313,"owners_count":20527678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-28T11:08:22.485Z","updated_at":"2025-03-22T02:15:10.181Z","avatar_url":"https://github.com/boredsquirrel.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Security-shutdown\nFour ways to automatically shutdown your Linux PC/Laptop if there is has no power supply attached.\n\nThe reasoning is simple: You dont want anyone to be able to touch your running system if they dont actually have to stay in your home.\n\nLUKS encryption is pretty strong, but if your Laptop is on and someone could take it somewhere, this may be weakened.\n\nUsing these little tools you can ensure they would always have to fight with LUKS and probably lose.\n\n## Method 1: udev rule\n\nIf your system supports this, use that. Its way simpler and should work immediately.\n\n```\nsudo cat \u003c\u003cEOF \u003e /etc/udev/rules.d/99-poweroff-no-power.rules\nSUBSYSTEM==\"power_supply\", ATTR{online}==\"0\", RUN+=\"/usr/bin/shutdown -h now\"\nEOF\n```\n\n## Method 2: upower\n\n```\nsudo cat \u003c\u003cEOF \u003e /etc/systemd/system/poweroff-no-power.service\n[Unit]\nDescription=Shutdown on power loss\nDefaultDependencies=no\nAfter=syslog.target\n\n[Service]\nType=oneshot\nExecStart=/usr/bin/upower -i /org/freedesktop/UPower/devices/battery_BAT0 | /bin/grep -q \"state: discharging\" \u0026\u0026 /sbin/shutdown -h now\n\n[Install]\nWantedBy=multi-user.target\nEOF\n```\n\n## Method 3: /bin/on_ac_power\n\nThis service executes every 10sec. Should be secure enough.\n\n```\nsudo cat \u003c\u003cEOF \u003e /etc/systemd/system/poweroff-no-power.service\n[Unit]\nDescription=Detect if there is no power and shut down the system\nAfter=network.target\n\n[Service]\nType=oneshot\nExecStart=/bin/bash -c \"while true; do\n    if ! /usr/bin/on_ac_power; then\n        /usr/bin/systemctl shutdown -h now\n    fi\n    sleep 10\ndone\"\nEOF\n```\n\n## Method 4: ACPI\nThis one might be a bit specific and not work everywhere\n\n```\nsudo cat \u003c\u003cEOF \u003e /etc/systemd/system/poweroff-no-power.service\n[Unit]\nDescription=Detect if there is no power and shut down the system\nAfter=network.target\n\n[Service]\nType=simple\nEnvironment=DISPLAY=:0\nExecStart=/usr/bin/acpi_listen | /usr/bin/grep --line-buffered \"ac_adapter ACPI0003:00 00000080 00000000\" | /usr/bin/xargs -I{} /usr/bin/shutdown -h now\n\n[Install]\nWantedBy=multi-user.target\nEOF\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboredsquirrel%2Fsecurity-shutdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboredsquirrel%2Fsecurity-shutdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboredsquirrel%2Fsecurity-shutdown/lists"}