A Raspberry Pi 3 Raspberry Pi (aka rpi) is a nice little thing. It is cheap, runs debian from an SD card. Doing anything on it is fast and easy, as long as you don’t use it as a device. headless Headless devices are those devices which don’t have peripherals like monitor, mouse or keyboard attached. They essentially are at their bare minimum: and . (These can run lightweight distros without GUI). The only way of accessing these machines is through a serial-to-usb adapter or ssh. Particularly, access through ssh presents its own problems. Power Networking How would you shutdown your headless rpi without network connectivity? There is an entire on reddit dedicated to shutting down headless pi’s. Most of the answers revolve around attaching a button to GPIO or buying an addon board. There are quite a lot of solutions involving buying stuff. thread Am I going to buy stuff? No way! Once upon a time, Stefan Tomanek wrote something named . In his words, triggerhappy Triggerhappy is a hotkey daemon developed with small and embedded systems in mind, e.g. linux based routers. It attaches to the input device files andinterprets the event data received and executes scripts configured in itsconfiguration. Just give me the steps already! To shutdown the pi, we are going to plug in a mouse into the pi’s USB and right click. We will configure daemon to listen for this event and call the shutdown command. triggerhappy Connect your mouse (or any other input device) to rpi. Find out the event name of your click/tap by running . This should list the events related to your click. In my case, it was for mouse right button down and for button up. Find the event code of trigger thd --dump /dev/input* BTN_RIGHT 1 BTN_RIGHT 0 **Create the shutdown script**Make a file with /etc/trigger.sh #!/bin/bash # Announce to all terminalswall 'A mouse forced me to shut down' # The actual shutdown command. sudo is used because shutdown# needs root previlagessudo /sbin/shutdown now Make the script executable sudo chmod +x /etc/trigger.sh Create a file with the following contents. (Replace with your trigger event code from the first step) Create the config file triggerhappy /etc/triggerhappy/triggers.d/mouse-poweroff.conf BTN_RIGHT BTN_RIGHT 1 /etc/trigger.sh Restart triggerhappy sudo systemctl restart triggerhappy.service Roadblock! Well, isn’t it supposed to work already? _Nope._triggerhappy, executes our script as a user called . According to , nobody wikipedia In many Unix variants, “ ” is the conventional name of a user account which owns no files, is in no privileged groups, and has no abilities except those which every other user has. Some systems also define an equivalent group “nogroup”. nobody The command to actually power off the pi. actually cannot execute any command with superuser privilages. We are going to bypass that now. We need to allow user to execute with without requiring password. shutdown needs root previlages nobody nobody shutdown sudo Now, will open an editor to edit the file. Append the following at the end, save and exit. sudo visudo sudoers # We add echo command for testing. Remove laternobody ALL =NOPASSWD: /bin/echo*,/sbin/shutdown* This is not a clean or secure way, since we are granting permission for to shutdown your pi. Warning: nobody To see if it works, from your current user and check if you can as . sudo su -s /bin/bash nobody sudo echo 'hello world' nobody And we’re done. Attach the mouse to your rpi, right click and watch the rpi turn off.