Skip to content

Instantly share code, notes, and snippets.

@pbhandari
Last active August 29, 2015 14:07
Show Gist options
  • Save pbhandari/6c619be223d4f195aba3 to your computer and use it in GitHub Desktop.
Save pbhandari/6c619be223d4f195aba3 to your computer and use it in GitHub Desktop.
A very simple local password manager
#!/usr/bin/sh
pass_file=$HOME/local_pass.gpg
recpt_name='CHANGE_ME'
if [ x"$recpt_name" = x'CHANGE_ME' ]; then
echo "Change the recpt_name to the email of your secret key"
exit 1
fi
if [ x"$1" = x'decrypt' ]; then
gpg --decrypt $pass_file | grep "$2:"
elif [ x"$1" = x'encrypt' ]; then
echo "Password: "; read -s PASSWORD
(gpg --decrypt $pass_file && echo $2: $PASSWORD) | \
gpg --encrypt --armor --recipient $recpt_name --output $pass_file --yes
elif [ x"$1" = x'generate' ]; then
cat /dev/urandom | base64 | head -c${2:-16}; echo
fi
# USAGE:
# ./local_pass.sh decrypt USER_NAME
# This will look through the $pass_file for a string that matches
# USER_NAME and prints that out.
#
# ./local_pass.sh encrypt USER_NAME
# This will add the username: password entry to the $pass_file.
#
# ./local_pass.sh generate LENGTH
# This will generate a super-secret and uncrackable password.
@pbhandari
Copy link
Author

Mind you this is a horrendously stupid way to do it, but it works .... kinda.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment