gpg: decryption failed: secret key not available

- Ubuntu -

Lately I decided to setup my own off-site backup (More on this soon), and because of that I wanted to implement encryption for those backups. Well today when testing opening my first backup I received this error: “gpg: decryption failed: secret key not available”.

It was easy to understand and fix once I understood what was happening. Myself having my Security+ certification, I should have known better than this… The reason is because when you encrypt something with your private key, it can only be decrypted with your private key. DUH! You are thinking to yourself: Wait a sec, what about public keys? What are those for?! Those are for when you want someone to encrypt something coming to you. Make sense? No. Ask below.

Anyway, if you are receiving the error above it’s because you need to import your private key on the machine you are attempting to open it on.

Step 1: Export the private key from the machine that did the encryption. In my case it’s my web server.

gpg --export-secret-key -a > secret.key

Let’s go ahead and do the public key to, while we are here.

gpg --output KEYNAME.gpg --export EMAIL-ADDRESS-YOU-USED-FOR-THE-KEY

Step 2: SFTP or SECURELY move them to the new PC or server.

Step 3: Import the keys into the new PC or server.

Public key:

gpg --import KEYNAME.gpg

Private key:

gpg --import secret.key

There you go. You should be able to decrypt it now! :)

More commands on the GPG handbook: http://www.gnupg.org/gph/en/manual/book1.html

I hope that helps someone out there!

Author:  Crimm

Software engineer (PHP, Bat, VBS), Sr. Systems Admin, Techie, Father, Gamer, Anime watcher (Wannabe Otaku), & full of geek!

  • http://hifisoundsystems.com Jed

    or just copy your ~.gnupg folders contents to the other machine which will also include the trustdb.gpg file. this file is important as it contains the verified sigs that will make your key trustworthy…

  • http://dives.byethost3.com/?p=1109 miedzywodzie

    This is really a really super read for me, Have to admit you happen to be first from the best bloggers I ever saw.Thanks for posting this informative article.