Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save swipswaps/5552a8d81aff8d1fca9a4fb41f01c0e5 to your computer and use it in GitHub Desktop.
Save swipswaps/5552a8d81aff8d1fca9a4fb41f01c0e5 to your computer and use it in GitHub Desktop.
Store and use secure passwords in bash
#!/bin/bash
# Mixing in python with bash we can easily retrieve our passwords securely in our shell scripts.
# Read this first: https://live.gnome.org/GnomeKeyring/SecurityPhilosophy
# Make sure your distro has gnome-keyring-daemon installed and running at login,
# as well as python-keyring installed (sudo apt-get install python-keyring)
##
# Follow these steps to see what it does. Verify by looking in Seahorse for your password.
##
# To make it easier for you, we'll setup the variables first
_PWNAME="Luggage" # A placeholder name for this password in the keychain
_ME="$(whoami)" # Logged in users name
_PW="12345" # Example password
# First, you need to store the password
python -c "import keyring;keyring.set_password('""$_PWNAME""','""$_ME""','""$_PW""')"
# If this command didn't print anything it should be stored.
# Accessing it is even easier:
PASSWORD=$(python -c "import keyring;print keyring.get_password('""$_PWNAME""', '""$_ME""')")
echo "$PASSWORD" # this should return the string '12345'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment