I have an accounts.org.gpg file. I can open it using gpg directly:

$ gpg -d ./accounts.org.gpg 

You need a passphrase to unlock the secret key for
user: "Omair Majid <removed@removed>"
4096-bit RSA key, ID 7CC8AAC6, created 2012-01-18 (main key ID 66484681)

gpg: encrypted with 4096-bit RSA key, ID 7CC8AAC6, created 2012-01-18
    "Omair Majid <removed@removed>"
+TITLE: Accounts
<rest of output removed>

But I can't open the same file using Emacs. Trying to open it in emacs gives me an error:

epa-file--find-file-not-found-function: Opening input file: Decryption failed, No secret key: E295ECEC7CC8AAC6

Is there something I need to configure on the emacs side to make this work?

For some additional background, I created this file on another machine (using the same version of Emacs), on which Emacs could read/write to that file just fine. I then copied over the contents of ~/.gnupg over to this machine. And now gpg can still read it, but Emacs can't.

EDIT: Could this be a gpg1 vs gpg2 difference?

$ gpg2 --decrypt accounts.org.gpg 
gpg: encrypted with RSA key, ID E295ECEC7CC8AAC6
gpg: decryption failed: No secret key

How was the Emacs on the other machine (using same configuration, same version of Emacs (25.1) and same OS (Fedora 24 x86_64, same version of gpg and gpg2 packages)) read from it and write to it. Anyway using,

(setq epg-gpg-program "/usr/bin/gpg")

Still results in the same error.

  • Have you tried (setq epg-gpg-program "gpg2") ?
    – caisah
    Commented Oct 16, 2016 at 7:11
  • I did. It's the default too. And it doesn't work. Just like the gpg2 command line program doesn't. I am starting to think this is a problem with gpg2 itself, not emacs at all.
    – omajid
    Commented Oct 16, 2016 at 23:04
  • 3
    @caisah See Bug #24229, setq doesn't work for epg-gpg-program, you have to customize it.
    – npostavs
    Commented Oct 17, 2016 at 16:09

1 Answer 1


You do not say which OS nor version of emacs you have.

I solved yesterday exactly the same problem in OSX and emacs 25.1 using information from this link: http://colinxy.github.io/software-installation/2016/09/24/emacs25-easypg-issue.html

I ran these commands:

brew unlink gnupg2 gpg-agent dirmngr
brew uninstall gnupg2 gpg-agent dirmngr
brew install gnupg21
ln -s /usr/local/bin/gpg2 /usr/local/bin/gpg

and set the pinentry mode in my emacs conf file:

(setf epa-pinentry-mode 'loopback)
  • Please see my edits for OS and Emacs versions. I definitely don't plan to override the system versions of gpg/gpg2.
    – omajid
    Commented Oct 17, 2016 at 14:51
  • The standard brew package gnupg has for some time now been version 2.1. Older versions 1.4 and 2.0 that are not fully compatible with it are available as separate packages.
    – Heikki
    Commented Jul 10, 2017 at 19:20
  • 3
    Thanks for pointing out the (setf epa-pinentry-mode 'loopback) trick.
    – phs
    Commented Mar 11, 2019 at 9:26
  • 2
    Adding the (setf epa-pinentry-mode 'loopback) line in .emacs was sufficient for my Gnu Emacs 26.2 with gpg 2.2.16 from homebrew.
    – Dave X
    Commented Sep 15, 2019 at 14:42
  • 1
    Apparently (setf epa-pinentry-mode 'loopback) is enough without needing to do all the brew operations.
    – xji
    Commented Feb 24, 2020 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.