GPG in headless system

While configuring GPG for backup with duplicity on a headless system I had any kind of issue with gpg-agent and pass phrases. This happened on a Centos 6 host.

It turns out that GPG needs to use a tty. This means that you cannot su su - in the user that needs its keys, but you have to directly login as the user, physically or through ssh.

Then, you can follow the man pages' advice:

eval $(gpg-agent --daemon)
export GPG_TTY

And now you can generate your keys.