USB-KEY
Lock/Unlock with USB Drive
Script to setup key and udev rules to lock and unlock a linux machine based on USB device insertion and removal.
Copy the script to a folder on a USB drive. Run script as root. Select the USB drive identifier. Indicate if you want a key pair. It can work without, key pair just increases security. When installation completed, just plug and unplug drive to lock. Note: the system must be already logged in to the user in order for locking and unlocking to work.
Choose a USB drive for usage. Size of installation after keys is less than 10k. Filesystem format only needs to be something the installation can read.
Create a subfolder for the the script file. You can put it in any folder including root of the usb drive. I create a folder USBKEY to keep things organized.
Copy script file to USB drive. It must run from the drive for proper path setups.
Run script as root from the drive. My drive is mounted at
/run/media/jtoebes/JToebes
Select the entry that corresponds to the drive. Cursor
Up/Down then press enter.
Confirm selection.
Decide if you want a keypair. Without a keypair any USB
matching the ID will be able to unlock. With a keypair after
plugin, the keys are checked to match.
If a rule file already exist, you will be asked to append
info. Current rules will be shown.
If you have run install before for the same drive, it may ask if you want to replace the lock script.
Script can be found at https://github.com/ToeJet/Scripts/tree/main/USBKEY