So it was time for a clean install on a larger SSD as my old system became completely unbootable (persistent initramfs uncompression error 😧).
However, I did not back up my GPG credentials 🤦.
I learned that retrieving them from the old system drive via chroot was technically possible but not a straightforward process.
-
Login to new Manjaro OS, run
yay -S manjaro-tools-base
. -
Put old Manjaro OS drive in external enclosure, plug it in.
-
Chroot into old Manjaro OS drive and within it, login as regular user.
sudo manjaro-chroot -a su - username42 # where `username42` is your regular username
-
You should now be in
/home/username42/
on the old drive.
The following steps are based on https://www.howtogeek.com/816878/how-to-back-up-and-restore-gpg-keys-on-linux.
-
Run
gpg --list-secret-keys --keyid-format LONG
, you should see your GPG key pair. -
Run
gpg --export --export-options backup --output public.gpg
, then exit the chroot environment and close the terminal.
Note: Apparently exporting secret keys to a private.gpg
does not work from a chroot environment, even as a regular user. Error was error receiving key from agent: Inappropriate ioctl for device - skipped
, anyone know how to overcome this?
-
On your main machine, copy
public.gpg
from the old drive to your new drive. -
Also copy the encrypted private key files (
*.key
) fromprivate-keys-v1.d
from old drive's~/.gnupg
to new drive's~/.gnupg
folder. -
On the new machine, run
gpg --import public.gpg
-
Your GPG credentials should now be ready to use on your new machine.
To avoid this messy situation, always back up your GPG credentials on your existing system when it is still healthy and accessible.
gpg --export --export-options backup --output public.gpg
gpg --export-secret-keys --export-options backup --output private.gpg
gpg --export-ownertrust >> trust.gpg
Copy these 3 files public.gpg
private.gpg
trust.gpg
to somewhere safe (like an external drive or NAS).
You can import them on a new machine by running
gpg --import public.gpg
gpg --import private.gpg # Prompts you to type the passphrase that you used when you first created the GPG key.
gpg --import-ownertrust trust.gpg
If you need to sign commits using your existing GPG key on your new machine, see https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key.