This document contains the final, working steps for:
- Creating a modern GPG keyring
- Adding an SSH authentication subkey
- Enabling
gpg-agentSSH support - Exposing the key via
ssh-agentcompatibility - Backing up the keyring safely
Tested with GnuPG 2.5.x in Termux.
pkg update
pkg install gnupg opensshCreate a modern ECC key:
gpg --full-generate-keyChoose:
(9) ECC (sign and encrypt)
Follow prompts and set a strong passphrase.
First get your full fingerprint:
gpg --list-secret-keys --with-subkey-fingerprintCopy the full 40-character fingerprint.
Add an authentication-only subkey:
gpg --quick-add-key FULL_FINGERPRINT ed25519 authVerify it exists:
gpg --list-secret-keysYou should see:
ssb ed25519 [A]
Create or edit:
~/.gnupg/gpg-agent.conf
Add:
enable-ssh-support
default-cache-ttl-ssh 300
max-cache-ttl-ssh 900
Restart the agent:
gpgconf --kill gpg-agent
gpgconf --launch gpg-agentAdd to your shell config (~/.bashrc or ~/.zshrc):
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)Reload shell:
source ~/.bashrcGnuPG 2.5 requires explicit approval of SSH keys.
Get keygrips:
gpg --list-secret-keys --with-keygripFind the keygrip for the [A] subkey.
Create or edit:
~/.gnupg/sshcontrol
Add the authentication subkey keygrip (one per line).
Example:
1234567890ABCDEF1234567890ABCDEF12345678
Restart agent again:
gpgconf --kill gpg-agent
gpgconf --launch gpg-agentCheck identities:
ssh-add -LYou should see:
ssh-ed25519 AAAA...
You can also export manually:
gpg --export-ssh-key FULL_FINGERPRINTAdd this public key to your Git hosting provider or servers.
Add to shell config:
alias lockssh='gpgconf --kill gpg-agent'Run:
locksshtar czf gnupg-backup.tar.gz ~/.gnupgStore securely offline.
gpg --export-secret-keys --armor FULL_FINGERPRINT > private-keys.ascOptional:
gpg --export-ownertrust > ownertrust.txtOn a new device:
rm -rf ~/.gnupg
tar xzf gnupg-backup.tar.gz -C ~
chmod 700 ~/.gnupg
gpgconf --kill gpg-agentSSH integration will work immediately.
You now have:
- Modern ECC GPG primary key
- Dedicated SSH authentication subkey
- gpg-agent acting as ssh-agent
- Auto-expiring SSH cache
- Clean backup & restore process
This setup works natively inside Termux without external password managers or traditional ssh-agent.