GnuPG 2.2 refuses secret key import: "error sending to agent: operation cancelled"
I'm trying to import my PGP identity including secret keys to a new computer by connecting to a computer which has the secret key, and running
ssh othercomputer cat myself.gpg | gpg2 --import
When doing this, it looks like GPG is importing the public keys, but not the private ones. When examining the output closer, I can see that it says "error sending to agent: operation cancelled" which I assume has something to do with the problem.
I have
- tried specifying a
pinentry-program
ingpg-agent.conf
; - restarted
gpg-agent
and triple-checked it is running; and - verified that the versions of gpg-agent and gpg match.
Solution 1:
The issue – I think – is that GnuPG detects that it is running in a pipe, i.e. in a non-interactive shell. Since non-interactive means there's no user interacting with it, there is little point in showing a pinentry dialog – at least in most cases.
The easiest solution is to store myself.gpg
on the local drive and then import it in a separate command. I understand this solution may have some repercussions in terms of privacy and secrecy, so do understand the consequences of this choice before you blindly follow advice.