Created
April 26, 2020 20:42
-
-
Save pythoninthegrass/eb5d68c73d25c6df4b2b7e1c368f3fa6 to your computer and use it in GitHub Desktop.
Store and use secure passwords in bash
This file contains hidden or 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 | |
# 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