Exporting a GPG Private Key | Generated by AI
Exporting a GPG Private Key from the Server
To export your private key, you’ll need access to the server via SSH or a terminal. GPG private keys are sensitive—handle them securely and delete the exported file after transfer.
- List your secret keys (to identify the key by email or key ID):
gpg --list-secret-keysLook for the entry like
sec rsa4096/ABC123DEF456 2023-01-01 [SC]. Note the email or key ID (e.g.,user@example.comorABC123DEF456). - Export the private key (use
--armorfor ASCII format, easier to transfer):gpg --export-secret-keys --armor user@example.com > private-key.asc- Replace
user@example.comwith your actual email or key ID. - This creates
private-key.ascin your current directory. - If you have multiple keys, specify the key ID for precision:
gpg --export-secret-keys --armor ABC123DEF456 > private-key.asc. - Security note: This exports the key without its passphrase. You’ll need to enter the passphrase on import if prompted.
- Replace
- Securely transfer the file to your local laptop:
- Use
scp(from your local machine):scp user@server-ip:/path/to/private-key.asc ./Replace
user@server-ipwith your server details and/path/to/with the actual path. - Alternatives:
rsyncfor larger files or SFTP for a GUI option. Avoid email or unsecured channels.
- Use
- Clean up on the server:
rm private-key.ascVerify it’s gone with
ls.
Importing the GPG Private Key on Your Local Laptop
Assuming you have GPG installed (e.g., via apt install gnupg on Linux, brew install gnupg on macOS, or Chocolatey on Windows).
- Import the key:
gpg --import private-key.asc- You’ll see output like “gpg: key ABC123DEF456: secret key imported”.
- If prompted for a passphrase during import, enter the original one.
- Verify the import:
gpg --list-secret-keysYour key should now appear under “sec”.
- Optional: Set trust level (if using for signing/email):
gpg --edit-key user@example.com- In the prompt, type
trust, select “ultimate” (option 5), thensaveandquit. - This marks the key as fully trusted on your local machine.
- In the prompt, type
Tips and Warnings
- Passphrase: Always use a strong one. If you forget it, the key becomes unusable.
- Subkeys: If your key has subkeys (e.g., for encryption), export them too with
--export-secret-subkeys. - Backup: Store exports in a secure vault (e.g., encrypted drive).
- Versions: Tested on GPG 2.x; works similarly on 1.x.
- For more details, see the official GPG docs: GnuPG Manual.