Backing Up and Restoring GPG Keys

By Ercan S. - 17/04/2025 - 0 comments

This guide outlines the steps to back up and restore your GPG keys, ensuring the security and continuity of your cryptographic identity.

Backing Up GPG Keys

1. Export the Secret Key

To back up your secret GPG key, use the following command:

gpg --export-secret-keys --armor > secret.asc

This command exports your secret key in ASCII format to the file `secret.asc`.

2. Export the Trust Database (Optional)

To back up your trust database, execute:

gpg --export-ownertrust > trustdb.txt

This will save your trust settings to `trustdb.txt`.

Restoring GPG Keys

1. Import the Secret Key

To restore your secret key from the backup, run:

gpg --import secret.asc

This command imports the secret key from the `secret.asc` file.

2. Import the Trust Database (Optional)

To restore your trust settings, execute:

gpg --import-ownertrust < trustdb.txt

This will import the trust settings from `trustdb.txt`.

3. Verify the Imported Key

To list your secret keys and verify the import, use:

gpg --list-secret-keys --keyid-format=long

4. Set Trust Level for the Key

To set the trust level for your imported key, execute:

gpg --edit-key <YourKeyID>
gpg> trust
gpg> quit

Replace `<YourKeyID>` with your actual key ID.

https://gnupg.org/download/

Tags: gpg