LockOMaticUSB is a Python-based security tool for macOS and Linux that automatically locks or logs off your computer when a designated USB or YubiKey device is removed, ensuring enhanced physical security.
- Implement USB uuid checking
- Make the config switch between mac/linux easier
- Test on windows
- Add best practices
- Add FAQ
- Add tested devices
- Python 3
- YubiKey Manager CLI (
ykman
)
-
Clone this repository:
git clone https://github.com/a7hybnj2/LockOMaticUSB.git cd LockOMaticUSB
-
Edit the
config.py
script and set thedevice_id
variable to the serial number of your YubiKey. If you don't know the serial number of your YubiKey, you can run the script with an emptydevice_id
and it will print the serial number of the connected YubiKey. -
Run the script:
python monitor.py
The script will now monitor for the presence of your YubiKey. If you remove the YubiKey, the script will lock the screen.
-
Implement your preferred method to automatically start the script. Examples include:
@reboot
in cron- plist & launchctl
- login items
- This script is currently configured for macOS. If you're using a different operating system, you might need to modify the
device_check_command
andlock_command
commands. Some alternative commands for Linux are included in the script, but they are commented out. - The script uses a lock file (
/tmp/LockOMaticUSB.lock
) to ensure that only one instance of the script is running at a time. - The script registers handlers for the
SIGINT
,SIGTERM
, andSIGQUIT
signals. If it receives one of these signals, it will print a message and exit. - The
debug
variable controls whether the script prints debug information. Ifdebug
isTrue
, the script will print messages when it checks for the YubiKey and when it locks the screen. Ifdebug
isFalse
, the script will not print these messages. - The
test
variable controls whether the script actually locks the screen. Iftest
isTrue
, the script will print a message instead of locking the screen when the YubiKey is removed. Iftest
isFalse
, the script will lock the screen when the YubiKey is removed.