Step-by-step guide to transfer and set up an old GPG key (for Git commit signing) on a new machine.
(Skip if you already have the key files)
gpg --export-secret-keys --armor YOUR_KEY_ID > private-key.asc- Replace
YOUR_KEY_IDwith your keyβs fingerprint or email.
gpg --export --armor YOUR_KEY_ID > public-key.ascgpg --export-ownertrust > trustdb.txtCopy these files to the new machine:
private-key.ascpublic-key.asc(optional, if needed)trustdb.txt(optional)
- Linux:
sudo apt install gnupg - Mac:
brew install gnupg - Windows: GPG4Win
gpg --import private-key.ascgpg --import public-key.ascgpg --import-ownertrust trustdb.txtgpg --list-secret-keys --keyid-format LONGCheck if your key appears.
git config --global user.signingkey YOUR_KEY_IDgit config --global commit.gpgsign truegit config --global tag.gpgsign truegit config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"(Skip if the key already exists in GitHub account)
- Get your public key:
gpg --armor --export YOUR_KEY_ID
- Paste it at:
GitHub β Settings β SSH and GPG Keys β New GPG Key
β Done! Your old GPG key is now active on the new system.