Pete's Linux Advent Calendar 2007

The 6th day

How to lock your terminal

Here is a little script that password protects your terminal session with a password:
#!/bin/bash
trap "echo Enter password to unlock:; /bin/stty -echo;" 2 15 20

export PATH=/usr/bin:/bin

/bin/stty -echo

echo "Enter passkey"
read keyword
clear
/bin/echo Enter Password to unlock:
while :
do
    read userinput
    if [ "$keyword" = "$userinput" ]; then
        break
    else
        echo Sorry
    fi
done

/bin/stty echo
If you run this script you will first be asked for the password, that you later have to type in again to unlock. You'll also notice that you cannot interrupt the script with Ctrl-C.
Pete's Linux Advent Calendar 2007

Valid HTML 4.01!

Comments? send mail to pkruse@arcor.de my monogram