Secrets Recovery
Overview
Post-restore procedure for SSH and GPG keys. After recovering from backup, keys must be decrypted and agents configured.
Post-Restore Checklist
# 1. Decrypt keys
~/.secrets/bin/decrypt-ssh-keys.sh
~/.secrets/bin/decrypt-gpg-keys.sh
# 2. Start SSH agent and load keys
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_* ~/.ssh/id_rsa_*
# 3. Verify
ssh-add -l
ssh -T git@github.com
gpg --list-secret-keys
echo "test" | gpg --sign --armor
SSH Agent Setup
Load SSH Keys
ssh-add ~/.ssh/id_ed25519_github
ssh-add ~/.ssh/id_ed25519_gitlab
ssh-add ~/.ssh/id_ed25519_codeberg
ssh-add ~/.ssh/id_ed25519_bitbucket
ssh-add ~/.ssh/id_rsa_azure
ssh-add ~/.ssh/id_ed25519_* ~/.ssh/id_rsa_*
ssh-add -l
ssh -T git@github.com
GPG Recovery
GPG Database Lock Issue
Symptom:
gpg: Note: database_open 134217901 waiting for lock (held by 244009) ...
gpg: keydb_search_first failed: Connection timed out
Cause: Stale lock files from terminated processes or synced .gnupg directories.
gpgconf --kill all
rm -f ~/.gnupg/public-keys.d/.#lk* 2>/dev/null
rm -f ~/.gnupg/public-keys.d/*.lock 2>/dev/null
gpg --list-secret-keys
GPG Lock Files from Synced .gnupg
When .gnupg is synced between machines, lock files from other hosts cause GPG to hang.
ls -la ~/.gnupg/public-keys.d/
# Shows .#lk* files with OTHER hostnames:
# .#lk0x00007f4254000ce0.modestus-x1.36661
rm -f ~/.gnupg/public-keys.d/.#lk*
rm -f ~/.gnupg/public-keys.d/pubring.db.lock
gpg --list-secret-keys
gpgconf --kill all
rm -f ~/.gnupg/public-keys.d/.#lk*
rm -f ~/.gnupg/public-keys.d/*.lock
Pinentry Configuration
Arch Linux
Arch requires gcr package for pinentry-gnome3:
gpg: signing failed: No pinentry
sudo pacman -S gcr
pkill -9 gpg-agent
rm -f /run/user/$(id -u)/gnupg/S.gpg-agent*
echo "test" | gpg --sign --armor
WSL / Headless Systems
WSL has no GUI. Use terminal pinentry:
sudo dnf install pinentry-tty -y
sudo pacman -S pinentry
echo "pinentry-program /usr/bin/pinentry-tty" >> ~/.gnupg/gpg-agent.conf
gpgconf --kill gpg-agent
export GPG_TTY=$(tty)
Add to .zshrc / .bashrc:
export GPG_TTY=$(tty)
Verification Commands
ssh-add -l
ssh -T git@github.com
gpg --list-secret-keys
echo "test" | gpg --sign --armor
ls -la ~/.gnupg/public-keys.d/*.lock 2>/dev/null
ps aux | grep -E "gpg|keybox" | grep -v grep
Credential Locations
| Credential | Storage | Access |
|---|---|---|
SSH keys |
|
|
GPG keys |
|
|
age key |
|
Direct file access |
LUKS passphrases |
gopass |
|
Borg passphrase |
gopass/dsec |
|
Service credentials |
dsec |
|