Without gpg-agent running, I can enter my passphrase to sign things:

$ echo 123 | gpg -s

You need a passphrase to unlock the secret key for
user: "Mr. Ops <[email protected]>"
2048-bit RSA key, ID 20F31903, created 2014-03-13

gpg: gpg-agent is not available in this session
Enter passphrase:

Works fine. But I don't want to type my passphrase all the time, so I run gpg-agent:

$  eval $(gpg-agent --daemon)

Now I would expect to be prompted for my passphrase at least once, but I never am, and all operations using gpg fail.

$ echo 123 | gpg -s

You need a passphrase to unlock the secret key for
user: "Mr. Ops <[email protected]>"
2048-bit RSA key, ID 20F31903, created 2014-03-13

gpg: cancelled by user
gpg: no default secret key: bad passphrase
gpg: signing failed: bad passphrase

How do I get my passphrase stored in the agent? Once I have it there, how do I keep it there across login sessions? (Ideally I never want to be prompted again.) This is on Ubuntu 12.04.4 with the standard apt-get gpg packages, in case it matters.

4 Answers 4


This happens when gpg-agent doesn't know which TTY to prompt on, which is happening here because you are redirecting stdin.

You can put export GPG_TTY=$(tty) in your ~/.bashrc to setup the TTY for each login shell.

The docs on gpg-agent has more details.

  • In principle there should be a mechanism to update the tty, so that should still work. Does gpg-agent have a pinentry program available for tty interaction? Mar 19, 2021 at 9:35

Kind of late, but at this time I face this problem when I do remote login to my PC (Linux-Centos) and try to decrypt a PGP file. I tried dave's suggestion, without luck, googling I found this

gpg: cancelled by user

This part solve my problem:

Finally after allowing other's to r+w on tty seem to solve this issue

[root@host ~]# chmod o+rw $(tty)

Hope this can help someone else.


  • This one would work.. Just do the chmod tty part before doing su to the user
    – user169015
    Jan 5, 2017 at 10:04
  • This is insecure -- you should ensure that the tty is owned by the correct user, or perhaps use a group with the required users in and group permissions :)
    – Legooolas
    Sep 9, 2019 at 11:31

I'm not sure if this will solve it, but I was experiencing similar issues. Log into a server, try to run gpg to decrypt a package,it says I need a passphrase, there's no way to enter that passphrase, gpg-agent is running, chmodding the tty didn't work, exporting GPG_TTY didn't work.

My problem was I had ssh'd into the server as root, then su <gpg-user account>. gpg-agent then did not have the access it needed to my ssh terminal, so running gpg to decrypt failed with the whole You need a passphrase to unlock the secret key for user: gpg: cancelled by user gpg: decryption failed: No secret key error.

SOLUTION was to ssh into the server as the gpg-user account I had encrypted with. That way the ssh terminal was owned by the gpg-user account, and when I ran gpg to decrypt some data, it could do it's funky stuff and wipe the screen and prompt for the passphrase.

Had me confused for ages, then this page made me think about the problem a bit - so thank you for the question and the other answers - you all really helped me out!


chmod o+rw $(tty) solved it for me. I was trying to create a pgp key on an ec2 instance while logged in through the session manager. After running this command, it finally prompted me for a password

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .