I've some stuff encrypted with GnuPG using gpg -e. When I decrypt them, the system does not ask for the passphrase, it decrypts it straight away.

Does it store the secret key somewhere and uses it (I also stored my secret key in the GnuPG key chain, does it uses that)?

How can I force the system to ask the passphrase every time?


5 Answers 5


Does it store the secret key somewhere and uses it (I also stored my secret key in the GnuPG key chain, does it uses that)?

GnuPG only uses keys from your key chain, so it must be in there to use it.

How can I force the system to ask the passphrase every time?

Old versions of GnuPG uses the gpg-agent, which caches the passphrase for a given time. Use the option --no-use-agent or add a line no-use-agent to ~/.gnupg/gpg.conf to prevent using the agent.

For newer versions (v2.1+), disable password caching for the agent by creating ~/.gnupg/gpg-agent.conf and adding the following lines:

default-cache-ttl 1
max-cache-ttl 1

Restart the agent with:

echo RELOADAGENT | gpg-connect-agent
  • 12
    Note that for gpg2 "--no-use-agent" is an obsolete option - it has no effect.
    – 10 cls
    Commented Nov 19, 2016 at 17:36
  • To be more specific, it is obsolete for GnuPG 2.1 (and newer).
    – Jens Erat
    Commented Nov 30, 2016 at 18:17
  • 5
    0 seems to mean no caching at all, as it correctly asks for passphrase even immediately after encrypting. I just wanted to add that the correct way to reload gpg-agent would be echo RELOADAGENT | gpg-connect-agent Commented Jan 10, 2017 at 13:01
  • 11
    It might be noteworthy that gpg-agent also caches passphrases used with gpg --symmetric, which allows anyone with access to the shell / gpg-agent-session to decrypt the file without entering the passphrase.
    – fbmd
    Commented Jan 14, 2017 at 11:33
  • 1
    GnuPG does not read a system-wide configuration file, so you need to roll out the configuration for all existing users and create it when creating new users (skeleton folder on Linux, don't know how to do so in Windows).
    – Jens Erat
    Commented Aug 24, 2018 at 6:37

GnuPG 2.2.15

          -c  Encrypt with a symmetric cipher using a passphrase. The default sym-
          metric cipher used is AES-128, but may be chosen with the  --cipher-algo
          option.  This command may be combined with --sign (for a signed and sym-
          metrically encrypted message), --encrypt (for  a  message  that  may  be
          decrypted  via  a  secret  key or a passphrase), or --sign and --encrypt
          together (for a signed message that may be decrypted via a secret key or
          a  passphrase).  gpg caches the passphrase used for symmetric encryption
          so that a decrypt operation may not require that the user needs to enter
          the  passphrase.   The  option  --no-symkey-cache can be used to disable
          this feature.
# encrypt files
gpg -c --no-symkey-cache file.txt
# decrypt files
gpg --no-symkey-cache file.txt.gpg

with --no-symkey-cache option, it will not cache your password

  • 1
    This works, but if I switch to another user, like root, it doesn't work--I get the error "gpg: problem with the agent: Permission denied" BUT there is a solution, "pinentry mode" gpg --pinentry-mode=loopback test.gpg askubuntu.com/a/1158297/429995
    – Jay Brunet
    Commented Apr 26, 2020 at 8:03
  • 2
    Although the man page doesn't mention it, you also need --no-symkey-cache when decrypting, as shown in this example.
    – ARX
    Commented Oct 10, 2020 at 17:04

Encrypting a "test" file should give us test.gpg

# gpg -c test

But no, we get some errors.

gpg: problem with the agent: Permission denied
gpg: error creating passphrase: Operation cancelled
gpg: symmetric encryption of 'test' failed: Operation cancelled

Loopback mode to the rescue!

# gpg -c --pinentry-mode=loopback test

It prompts for your password and works as expected.

When it comes time to decrypt, maybe you change users and get an error:

gpg: problem with the agent: Permission denied

Loopback mode to the rescue!

# gpg --pinentry-mode=loopback test.gpg

Tested with...

gpg (GnuPG) 2.2.20
libgcrypt 1.8.5

IMO --pinentry-mode=loopback and --no-symkey-cache should be the default settings. I found the solution here https://askubuntu.com/a/1158297/429995 and the "anonymous" answer here (to not cache the password) was helpful as well.

  • --no-symkey-cache is not an option in version 2.2.5.
    – rwst
    Commented Jun 29, 2022 at 14:46

For gpg version 2.2.4 the following work using symmetric and adding --batch to the gpg command:

Therefore, to clear the password stored in the session, we can run:

echo RELOADAGENT | gpg-connect-agent

More info in this tutorial: https://www.baeldung.com/linux/encrypt-decrypt-files


Some pinentry implementations cache the decryption keys in the desktops keystore, you can disable that functionality by using --no-allow-external-cache (documentation):

Tell Pinentry not to enable features which use an external cache for passphrases.

Some desktop environments prefer to unlock all credentials with one master password and may have installed a Pinentry which employs an additional external cache to implement such a policy. By using this option the Pinentry is advised not to make use of such a cache and instead always ask the user for the requested passphrase.

You must log in to answer this question.

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