Skip to content

Instantly share code, notes, and snippets.

@OliPelz
Last active March 22, 2023 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OliPelz/1d9cc1b0146dc38bd970ec4e71d9f89a to your computer and use it in GitHub Desktop.
Save OliPelz/1d9cc1b0146dc38bd970ec4e71d9f89a to your computer and use it in GitHub Desktop.
load all ssh keys from keepass/passhole and store in local ssh keys
#!/bin/bash
set -e
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo -n Enter password to decrypt keepass file:
read -s keepass_password
# load keepass db for the first time so we can set a password
ph --database ~/.local/share/passhole/Automation-readonly.kdbx --password $keepass_password ls
touch ~/.ssh/config
chmod 600 ~/.ssh/config
ph --database ~/.local/share/passhole/Automation-readonly.kdbx show ssh/github.com/OliPelz --field password | base64 -d > ~/.ssh/id_ed25519_github.com_OliPelz
ph --database ~/.local/share/passhole/Automation-readonly.kdbx show ssh/github.com/OliPelz --field notes | base64 -d > ~/.ssh/id_ed25519_github.com_OliPelz.pub
chmod 600 ~/.ssh/id_ed25519_github.com_OliPelz
chmod 644 ~/.ssh/id_ed25519_github.com_OliPelz.pub
grep -q "Host github-OliPelz" ~/.ssh/config || echo "Host github-OliPelz
Hostname github.com
IdentityFile ~/.ssh/id_ed25519_github.com_OliPelz
IdentitiesOnly yes
" >> ~/.ssh/config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment