Export and import GPG keys in Windows and WSL
The last week I had to change my computer, so i had to move my whole development environment including my GPG keys that I use with GitHub because I want to continue using them on the new computer. So, in this post I will show you the process I followed to successfully export and import my GPG keys.
Requirements
- A GPG program, like GnuPG (To install one you can check my previous post).
- Existent GPG key to export (You can create one following this steps).
Export GPG key
First list your keys by looking for the key to export:
gpg --list-keys
Copy the uid of the key and export it using:
gpg --export -a $KEY_UID > public.key
Your public GPG key was successfully exported, now export your private key using:
gpg --export-secret-key -a $KEY_UID > private key
That’s all, your GPG key was successfully exported and you are ready to import it on your new computer.
Import the key
Before importing the keys we must to change their encoding to
UTF-8 without BOM
, because by default they are exported usingUTF-16 with BOM
, to convert them you can use:(Get-Content -path public.key) | Set-Content -Encoding UTF8 -Path public.utf8.key (Get-Content -path public.key) | Set-Content -Encoding UTF8 -Path private.utf8.key
Now we can import them using:
gpg --import public.utf8.key gpg --import private.utf8.key
Now you can check your freshly imported keys using:
gpg --list-keys gpg --list-secret-keys
That’s all, now you can configure git to sign your commits by default following my previous post
Categories
Automation scripting Development tools Front end web development Infrastructure Kubernetes Programming guide Security Software architectureTags
Recent Posts