-
-
Save PhilT/2371406 to your computer and use it in GitHub Desktop.
Simple way to store and retrieve website passwords encrypted with a master password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://gist.github.com/2371406 | |
# version 0.1 - Not much error handling yet. | |
# version 0.2 - Added --edit command | |
# | |
# Add to ~/bin/pw and chmod +x it. | |
# See bottom of file for usage. | |
PASSWORD_FILE=~/Documents/.passwords.csv | |
function cancel_input { | |
stty $stty_orig | |
echo 'Cancelled.' | |
exit | |
} | |
function enter_password { | |
trap cancel_input SIGINT | |
stty_orig=`stty -g` | |
stty -echo | |
read secret | |
stty $stty_orig | |
trap SIGINT | |
} | |
if [[ $# > 0 ]]; then | |
echo 'Enter encryption password:' | |
enter_password | |
OPTIONS=--force-mdc\ --no-tty\ -q\ --no-use-agent\ --yes\ --passphrase=$secret | |
fi | |
function encrypt { | |
gpg $OPTIONS -c -o $PASSWORD_FILE.gpg $PASSWORD_FILE | |
rm -f $PASSWORD_FILE | |
} | |
function decrypt { | |
gpg $OPTIONS -o $PASSWORD_FILE $PASSWORD_FILE.gpg | |
} | |
function init_password_csv { | |
encrypt | |
} | |
function edit_password_csv { | |
decrypt | |
nano $PASSWORD_FILE | |
encrypt | |
} | |
function add_password { | |
echo 'Enter password to add:' | |
enter_password | |
pass=$secret | |
decrypt | |
echo $1,$2,$pass >> $PASSWORD_FILE | |
encrypt | |
} | |
function find_password { | |
decrypt | |
echo Passwords that match "$1": | |
cat $PASSWORD_FILE | grep $1 | |
rm -f $PASSWORD_FILE | |
} | |
if [ $# == 2 ]; then | |
add_password $1 $2 | |
elif [ $# == 1 ]; then | |
if [ $1 == '--init' ]; then | |
init_password_csv | |
elif [ $1 == '--edit' ]; then | |
edit_password_csv | |
else | |
find_password $1 | |
fi | |
else | |
echo 'Usage (1): pw --init Encrypts a prepared .passwords.csv file' | |
echo 'Usage (2): pw --edit Edit the .passwords.csv file' | |
echo 'Usage (3): pw TERM find a password' | |
echo 'Usage (4): pw URL/NAME LOGIN add a password (prompted to enter)' | |
echo 'Add or view a password from a GPG encrypted password file.' | |
echo | |
echo 'TERM Term to search for. Can be either a URL, NAME or LOGIN' | |
echo 'URL/NAME A name or URL of a site' | |
echo 'LOGIN Email address or username used to login' | |
echo | |
exit | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An updated version is now in my bin repo at https://github.com/PhilT/bin.