Last active
August 29, 2015 14:06
-
-
Save prologic/9c23ee847678653b4a1c to your computer and use it in GitHub Desktop.
Password Management with bash and ccrypt
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 | |
function getpass() { | |
if [[ -f $HOME/.passwd.cpt ]]; then | |
password=$(ccrypt -c $HOME/.passwd.cpt | egrep $1 | cut -f 3 -d ":") | |
else | |
password=$(egrep $1 $HOME/.passwd | cut -f 3 -d ":") | |
fi | |
if [[ $password == "" ]]; then | |
echo "No matching password found!" | |
else | |
echo -n $password | pbcopy | |
echo "Password copied to clipboard!" | |
fi | |
} | |
function showpass() { | |
if [[ -f $HOME/.passwd.cpt ]]; then | |
password=$(ccrypt -c $HOME/.passwd.cpt | egrep $1 | cut -f 3 -d ":") | |
else | |
password=$(egrep $1 $HOME/.passwd | cut -f 3 -d ":") | |
fi | |
if [[ $password == "" ]]; then | |
echo "No matching password found!" | |
else | |
echo -n $password | |
fi | |
} | |
function remotepass() { | |
NAME=${1} | |
# XXX: Make the default hostname configurable via a $HOME/.passwdrc ? | |
HOST=${2:-myhome} | |
ssh -q -t ${HOST} "bash -l -c 'showpass ${NAME}'" | |
} | |
function addpass() { | |
NAME=${1} | |
USER=${2} | |
PASS=${3:-$(mkpasswd)} | |
if [[ -f $HOME/.passwd.cpt ]]; then | |
echo "Decrypting Password Database ..." | |
ccdecrypt $HOME/.passwd.cpt | |
fi | |
echo "${NAME}:${USER}:${PASS}" >> $HOME/.passwd | |
echo "Encrypting Password Database ..." | |
ccencrypt $HOME/.passwd | |
echo -n $PASS | pbcopy | |
echo "Password created and copied to clipboard!" | |
} | |
function syncpasswd() { | |
if [[ -f $HOME/.passwd ]]; then | |
echo "Encrypting Password Database ..." | |
ccencrypt $HOME/.passwd | |
fi | |
# XXX: Generlize this | |
scp .passwd.cpt home:.passwords/my_company.cpt | |
scp .passwd.cpt dev:backups | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment