Using Emacs’ EasyPG in text terminals

There is a bug in the integration between Emacs’ EasyPG and the “new” GnuPG2 that causes Emacs to not load .gpg files when running in a text terminal.  It’s being worked on, apparently, but in the mean-time, here is how to fix it.

The only solution I’ve found that works is to install a copy of GnuPG1 concurrent with the new GnuPG2.  They can live happily side-by-side.  Once you’ve done that, you need to tell EasyPG to use the old program rather than the new one. Full details are on the Emacs Wiki, here it is in a nutshell:

  • You can find an RPM package of GnuPG1 for openSUSE on the openSUSE Build Service
  • Once installed, you need to customize the variable epg-gpg-program.  Either use M-x customize to set it for all future sessions, or see my code snippet below that I put in my start-up scripts.  It should be set to the value “/usr/bin/gpg1” (or wherever gpg1 is installed on your platform)
  • Now when EasyPG opens a .gpg file, it will prompt for the passphrase in the Emacs minibuffer, instead of trying to use the gpg-agent and calling the pinentry program (which causes Emacs to hang in text mode)

 

If you like to use the gpg agent and graphical pinentry programs and only want to override GnuPG2 with GnuPG1 when running Emacs in a text terminial, then you can put code like this in your Emacs start-up (mine goes in ~/.emacs.d/<username>.el because I use the Emacs Starter Kit):

(when (not (display-graphic-p))
  (setq epg-gpg-program "/usr/bin/gpg1")) ; use GnuPG1 in text terminals

Enjoy!

Advertisements

2 thoughts on “Using Emacs’ EasyPG in text terminals

  1. Arch Linux also got gpg2 now, I installed gnupg1 from AUR, then did:

    (when (.archp) ; only on my arch machines
    (setq epg-gpg-program “/usr/bin/gpg1”)) ; there’s a pinentry bug in GnuPG2
    (defadvice epg–start (around advice-epg-disable-agent disable)
    “Don’t allow epg–start to use gpg-agent in plain text
    terminals.”
    (if (display-graphic-p)
    ad-do-it
    (let ((agent (getenv “GPG_AGENT_INFO”)))
    (setenv “GPG_AGENT_INFO” nil) ; give us a usable text password prompt
    ad-do-it
    (setenv “GPG_AGENT_INFO” agent))))
    (ad-enable-advice ‘epg–start ‘around ‘advice-epg-disable-agent)
    (ad-activate ‘epg–start)

    This lets me use the same emacs instance on text terminals and X, and at least in X I get to remember the password. I know epa can cache the password, but the help for that variable says it’s insecure, so I’d rather wait for a better pinentry to show up.

    • Sorry, those first two lines should be

      (when (file-executable-p “/usr/bin/gpg1”)
      (setq epg-gpg-program “/usr/bin/gpg1”))

Comments are closed.