Skip to content

Instantly share code, notes, and snippets.

@mhogerheijde
Last active March 2, 2016 08:42
Show Gist options
  • Save mhogerheijde/3402bfa8a5d5208179b1 to your computer and use it in GitHub Desktop.
Save mhogerheijde/3402bfa8a5d5208179b1 to your computer and use it in GitHub Desktop.
Automatically lock current session when your Yubikey is removed (or when any other event happens).
#!/bin/bash
log="/var/log/yubilock.log"
#yubimap="/etc/sysconfig/yubikeys"
userid=`ps auxn | grep -v root | grep gnome-session | head -n 1 | awk '{print $1}'`
user=`id -nu $userid`
sessionids=`/bin/loginctl list-sessions | grep ${user} | awk '{print $1}'`
for id in $sessionids; do
echo "$(date) [SCREENLOCK] $user $id '$0' '$1'" >> ${log}
/bin/loginctl lock-session $id
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment