Linux "gpg-agent" Command Line Options and Examples
Secret key management for GnuPG

gpg-agent is a daemon to manage secret (private) keys independently from any protocol. It is used as a backend for gpg and gpgsm as well as for a couple of other utilities. The agent is automatically started on demand by gpg, gpgsm, gpgconf, or gpg-connect-agent.


Usage:

gpg-agent [--homedir dir] [--options file] [options]
gpg-agent [--homedir dir] [--options file] [options] --server
gpg-agent [--homedir dir] [--options file] [options] --daemon [command_line]






Command Line Options:

--options
Reads configuration from file instead of from the default per-user configuration file. The default configuration file isnamed ‘gpg-agent.conf’ and expected in the ‘.gnupg’ directory directly below the home directory of the user. This option isignored if used in an options file.
gpg-agent --options ...
--homedir
Set the name of the home directory to dir. If this option is not used, the home directory defaults to ‘~/.gnupg’. It is onlyrecognized when given on the command line. It also overrides any home directory stated through the environment variable‘GNUPGHOME’ or (on Windows systems) by means of the Registry entry HKCU\Software\GNU\GnuPG:HomeDir.On Windows systems it is possible to install GnuPG as a portable application. In this case only this command line option isconsidered, all other ways to set a home directory are ignored.To install GnuPG as a portable application under Windows, create an empty file named ‘gpgconf.ctl’ in the same directory asthe tool ‘gpgconf.exe’. The root of the installation is then that directory; or, if ‘gpgconf.exe’ has been installed directlybelow a directory named ‘bin’, its parent directory. You also need to make sure that the following directories exist and arewritable: ‘ROOT/home’ for the GnuPG home and ‘ROOT/var/cache/gnupg’ for internal cache files.
gpg-agent --homedir ...
--verbose
Outputs additional information while running. You can increase the verbosity by giving several verbose commands to gpg-agent,such as '-vv'.
gpg-agent --verbose ...
--quiet
Try to be as quiet as possible.
gpg-agent --quiet ...
--batch
Don't invoke a pinentry or do any other thing requiring human interaction.
gpg-agent --batch ...
--faked-system-time
This option is only useful for testing; it sets the system time back or forth to epoch which is the number of seconds elapsedsince the year 1970.
gpg-agent --faked-system-time ...
--debug-level
Select the debug level for investigating problems. level may be a numeric value or a keyword:none No debugging at all. A value of less than 1 may be used instead of the keyword.basic Some basic debug messages. A value between 1 and 2 may be used instead of the keyword.advancedMore verbose debug messages. A value between 3 and 5 may be used instead of the keyword.expert Even more detailed messages. A value between 6 and 8 may be used instead of the keyword.guru All of the debug messages you can get. A value greater than 8 may be used instead of the keyword. The creation of hashtracing files is only enabled if the keyword is used.How these messages are mapped to the actual debugging flags is not specified and may change with newer releases of this program. Theyare however carefully selected to best aid in debugging.
gpg-agent --debug-level ...
--debug
This option is only useful for debugging and the behavior may change at any time without notice. FLAGS are bit encoded andmay be given in usual C-Syntax. The currently defined bits are:0 (1) X.509 or OpenPGP protocol related data1 (2) values of big number integers2 (4) low level crypto operations5 (32) memory allocation6 (64) caching7 (128)show memory statistics9 (512)write hashed data to files named dbgmd-000*10 (1024)trace Assuan protocol12 (4096)bypass all certificate validation
gpg-agent --debug ...
--debug-all
Same as --debug=0xffffffff
gpg-agent --debug-all ...
--debug-wait
When running in server mode, wait n seconds before entering the actual processing loop and print the pid. This gives time toattach a debugger.
gpg-agent --debug-wait ...
--debug-quick-random
This option inhibits the use of the very secure random quality level (Libgcrypt’s GCRY_VERY_STRONG_RANDOM) and degrades allrequest down to standard random quality. It is only used for testing and should not be used for any production quality keys.This option is only effective when given on the command line.On GNU/Linux, another way to quickly generate insecure keys is to use rngd to fill the kernel's entropy pool with lower qual‐ity random data. rngd is typically provided by the rng-tools package. It can be run as follows: 'sudo rngd -f -r /dev/uran‐dom'.
gpg-agent --debug-quick-random ...
--debug-pinentry
This option enables extra debug information pertaining to the Pinentry. As of now it is only useful when used along with
gpg-agent --debug-pinentry ...
--no-detach
Don't detach the process from the console. This is mainly useful for debugging.
gpg-agent --no-detach ...
--no-grab
Tell the pinentry to grab the keyboard and mouse. This option should be used on X-Servers to avoid X-sniffing attacks. Anyuse of the option --grab overrides an used option --no-grab. The default is --no-grab.
gpg-agent --no-grab ...
--log-file
Append all logging output to file. This is very helpful in seeing what the agent actually does. Use ‘socket://’ to log tosocket. If neither a log file nor a log file descriptor has been set on a Windows platform, the Registry entry HKCU\Soft‐ware\GNU\GnuPG:DefaultLogFile, if set, is used to specify the logging output.
gpg-agent --log-file ...
--no-allow-mark-trusted
Do not allow clients to mark keys as trusted, i.e. put them into the ‘trustlist.txt’ file. This makes it harder for users toinadvertently accept Root-CA keys.
gpg-agent --no-allow-mark-trusted ...
--allow-preset-passphrase
This option allows the use of gpg-preset-passphrase to seed the internal cache of gpg-agent with passphrases.
gpg-agent --allow-preset-passphrase ...
--allow-loopback-pinentry
Disallow or allow clients to use the loopback pinentry features; see the option pinentry-mode for details. Allow is thedefault.The --force option of the Assuan command DELETE_KEY is also controlled by this option: The option is ignored if a loopbackpinentry is disallowed.
gpg-agent --allow-loopback-pinentry ...
--no-allow-external-cache
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 whichemploys an additional external cache to implement such a policy. By using this option the Pinentry is advised not to make useof such a cache and instead always ask the user for the requested passphrase.
gpg-agent --no-allow-external-cache ...
--allow-emacs-pinentry
Tell Pinentry to allow features to divert the passphrase entry to a running Emacs instance. How this is exactly handleddepends on the version of the used Pinentry.
gpg-agent --allow-emacs-pinentry ...
--ignore-cache-for-signing
This option will let gpg-agent bypass the passphrase cache for all signing operation. Note that there is also a per-sessionoption to control this behavior but this command line option takes precedence.
gpg-agent --ignore-cache-for-signing ...
--default-cache-ttl
Set the time a cache entry is valid to n seconds. The default is 600 seconds. Each time a cache entry is accessed, theentry's timer is reset. To set an entry's maximum lifetime, use max-cache-ttl.
gpg-agent --default-cache-ttl ...
--default-cache-ttl-ssh
Set the time a cache entry used for SSH keys is valid to n seconds. The default is 1800 seconds. Each time a cache entry isaccessed, the entry's timer is reset. To set an entry's maximum lifetime, use max-cache-ttl-ssh.
gpg-agent --default-cache-ttl-ssh ...
--max-cache-ttl
Set the maximum time a cache entry is valid to n seconds. After this time a cache entry will be expired even if it has beenaccessed recently or has been set using gpg-preset-passphrase. The default is 2 hours (7200 seconds).
gpg-agent --max-cache-ttl ...
--max-cache-ttl-ssh
Set the maximum time a cache entry used for SSH keys is valid to n seconds. After this time a cache entry will be expiredeven if it has been accessed recently or has been set using gpg-preset-passphrase. The default is 2 hours (7200 seconds).
gpg-agent --max-cache-ttl-ssh ...
--enforce-passphrase-constraints
Enforce the passphrase constraints by not allowing the user to bypass them using the ``Take it anyway'' button.
gpg-agent --enforce-passphrase-constraints ...
--min-passphrase-len
Set the minimal length of a passphrase. When entering a new passphrase shorter than this value a warning will be displayed.Defaults to 8.
gpg-agent --min-passphrase-len ...
--min-passphrase-nonalpha
Set the minimal number of digits or special characters required in a passphrase. When entering a new passphrase with lessthan this number of digits or special characters a warning will be displayed. Defaults to 1.
gpg-agent --min-passphrase-nonalpha ...
--check-passphrase-pattern
Check the passphrase against the pattern given in file. When entering a new passphrase matching one of these pattern a warn‐ing will be displayed. file should be an absolute filename. The default is not to use any pattern file.Security note: It is known that checking a passphrase against a list of pattern or even against a complete dictionary is notvery effective to enforce good passphrases. Users will soon figure up ways to bypass such a policy. A better policy is toeducate users on good security behavior and optionally to run a passphrase cracker regularly on all users passphrases to catchthe very simple ones.
gpg-agent --check-passphrase-pattern ...
--max-passphrase-days
Ask the user to change the passphrase if n days have passed since the last change. With --enforce-passphrase-constraints setthe user may not bypass this check.
gpg-agent --max-passphrase-days ...
--enable-passphrase-history
This option does nothing yet.
gpg-agent --enable-passphrase-history ...
--pinentry-invisible-char
This option asks the Pinentry to use char for displaying hidden characters. char must be one character UTF-8 string. APinentry may or may not honor this request.
gpg-agent --pinentry-invisible-char ...
--pinentry-timeout
This option asks the Pinentry to timeout after n seconds with no user input. The default value of 0 does not ask the pinentryto timeout, however a Pinentry may use its own default timeout value in this case. A Pinentry may or may not honor thisrequest.
gpg-agent --pinentry-timeout ...
--pinentry-program
Use program filename as the PIN entry. The default is installation dependent. With the default configuration the name of thedefault pinentry is ‘pinentry’; if that file does not exist but a ‘pinentry-basic’ exist the latter is used.On a Windows platform the default is to use the first existing program from this list: ‘bin\pinentry.exe’,‘..\Gpg4win\bin\pinentry.exe’, ‘..\Gpg4win\pinentry.exe’, ‘..\GNU\GnuPG\pinentry.exe’, ‘..\GNU\bin\pinentry.exe’, ‘bin\pinen‐try-basic.exe’ where the file names are relative to the GnuPG installation directory.
gpg-agent --pinentry-program ...
--pinentry-touch-file
By default the filename of the socket gpg-agent is listening for requests is passed to Pinentry, so that it can touch thatfile before exiting (it does this only in curses mode). This option changes the file passed to Pinentry to filename. Thespecial name /dev/null may be used to completely disable this feature. Note that Pinentry will not create that file, it willonly change the modification and access time.
gpg-agent --pinentry-touch-file ...
--scdaemon-program
Use program filename as the Smartcard daemon. The default is installation dependent and can be shown with the gpgconf com‐mand.
gpg-agent --scdaemon-program ...
--disable-scdaemon
Do not make use of the scdaemon tool. This option has the effect of disabling the ability to do smartcard operations. Note,that enabling this option at runtime does not kill an already forked scdaemon.
gpg-agent --disable-scdaemon ...
--disable-check-own-socket
gpg-agent employs a periodic self-test to detect a stolen socket. This usually means a second instance of gpg-agent has takenover the socket and gpg-agent will then terminate itself. This option may be used to disable this self-test for debuggingpurposes.
gpg-agent --disable-check-own-socket ...
--use-standard-socket-p
Since GnuPG 2.1 the standard socket is always used. These options have no more effect. The command gpg-agent --use-standard-socket-p will thus always return success.
gpg-agent --use-standard-socket-p ...
--xauthority
These options are used with the server mode to pass localization information.
gpg-agent --xauthority ...
--keep-display
Ignore requests to change the current tty or X window system's DISPLAY variable respectively. This is useful to lock thepinentry to pop up at the tty or display you started the agent.
gpg-agent --keep-display ...
--listen-backlog
Set the size of the queue for pending connections. The default is 64.
gpg-agent --listen-backlog ...
--extra-socket
The extra socket is created by default, you may use this option to change the name of the socket. To disable the creation ofthe socket use ``none'' or ``/dev/null'' for name.Also listen on native gpg-agent connections on the given socket. The intended use for this extra socket is to setup a Unixdomain socket forwarding from a remote machine to this socket on the local machine. A gpg running on the remote machine maythen connect to the local gpg-agent and use its private keys. This enables decrypting or signing data on a remote machinewithout exposing the private keys to the remote machine.
gpg-agent --extra-socket ...
--enable-extended-key-format
This option creates keys in the extended private key format. Changing the passphrase of a key will also convert the key tothat new format. Using this option makes the private keys unreadable for gpg-agent versions before 2.1.12. The advantage ofthe extended private key format is that it is text based and can carry additional meta data. Note that this option alsochanges the key protection format to use OCB mode.
gpg-agent --enable-extended-key-format ...
--enable-putty-support
The OpenSSH Agent protocol is always enabled, but gpg-agent will only set the SSH_AUTH_SOCK variable if this flag is given.In this mode of operation, the agent does not only implement the gpg-agent protocol, but also the agent protocol used byOpenSSH (through a separate socket). Consequently, it should be possible to use the gpg-agent as a drop-in replacement forthe well known ssh-agent.SSH Keys, which are to be used through the agent, need to be added to the gpg-agent initially through the ssh-add utility.When a key is added, ssh-add will ask for the password of the provided key file and send the unprotected key material to theagent; this causes the gpg-agent to ask for a passphrase, which is to be used for encrypting the newly received key and stor‐ing it in a gpg-agent specific directory.Once a key has been added to the gpg-agent this way, the gpg-agent will be ready to use the key.Note: in case the gpg-agent receives a signature request, the user might need to be prompted for a passphrase, which is neces‐sary for decrypting the stored key. Since the ssh-agent protocol does not contain a mechanism for telling the agent on whichdisplay/terminal it is running, gpg-agent's ssh-support will use the TTY or X display where gpg-agent has been started. Toswitch this display to the current one, the following command may be used:gpg-connect-agent updatestartuptty /byeAlthough all GnuPG components try to start the gpg-agent as needed, this is not possible for the ssh support because ssh does notknow about it. Thus if no GnuPG tool which accesses the agent has been run, there is no guarantee that ssh is able to use gpg-agentfor authentication. To fix this you may start gpg-agent if needed using this simple command:gpg-connect-agent /byeAdding the --verbose shows the progress of starting the agent.The --enable-putty-support is only available under Windows and allows the use of gpg-agent with the ssh implementation putty. Thisis similar to the regular ssh-agent support but makes use of Windows message queue as required by putty.
gpg-agent --enable-putty-support ...
--ssh-fingerprint-digest
Select the digest algorithm used to compute ssh fingerprints that are communicated to the user, e.g. in pinentry dialogs.OpenSSH has transitioned from using MD5 to the more secure SHA256.
gpg-agent --ssh-fingerprint-digest ...
--auto-expand-secmem
Allow Libgcrypt to expand its secure memory area as required. The optional value n is a non-negative integer with a suggestedsize in bytes of each additionally allocated secure memory area. The value is rounded up to the next 32 KiB; usual C styleprefixes are allowed. For an heavy loaded gpg-agent with many concurrent connection this option avoids sign or decrypt errorsdue to out of secure memory error returns.
gpg-agent --auto-expand-secmem ...
--s2k-count
Specify the iteration count used to protect the passphrase. This option can be used to override the auto-calibration done bydefault. The auto-calibration computes a count which requires 100ms to mangle a given passphrase.To view the actually used iteration count and the milliseconds required for an S2K operation use:gpg-connect-agent 'GETINFO s2k_count' /byegpg-connect-agent 'GETINFO s2k_time' /byeTo view the auto-calibrated count use:gpg-connect-agent 'GETINFO s2k_count_cal' /byeEXAMPLESIt is important to set the environment variable GPG_TTY in your login shell, for example in the ‘~/.bashrc’ init script:export GPG_TTY=$(tty)If you enabled the Ssh Agent Support, you also need to tell ssh about it by adding this to your init script:unset SSH_AGENT_PIDif [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; thenexport SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"fiFILESThere are a few configuration files needed for the operation of the agent. By default they may all be found in the current homedirectory (see: [option --homedir]).gpg-agent.confThis is the standard configuration file read by gpg-agent onstartup. It may contain any valid long option; the leadingtwo dashes may not be entered and the option may not be abbreviated.This file is also read after a SIGHUP however only a fewoptions will actually have an effect. This default name may bechanged on the command line (see: [option --options]).You should backup this file.trustlist.txtThis is the list of trusted keys. You should backup this file.Comment lines, indicated by a leading hash mark, as well as emptylines are ignored. To mark a key as trusted you need to enter itsfingerprint followed by a space and a capital letter S. Colonsmay optionally be used to separate the bytes of a fingerprint; thisenables cutting and pasting the fingerprint from a key listing output. Ifthe line is prefixed with a ! the key is explicitly marked asnot trusted.Here is an example where two keys are marked as ultimately trustedand one as not trusted:.RS 2# CN=Wurzel ZS 3,O=Intevation GmbH,C=DEA6935DD34EF3087973C706FC311AA2CCF733765B S# CN=PCA-1-Verwaltung-02/O=PKI-1-Verwaltung/C=DEDC:BD:69:25:48:BD:BB:7E:31:6E:BB:80:D3:00:80:35:D4:F8:A6:CD S# CN=Root-CA/O=Schlapphuete/L=Pullach/C=DE!14:56:98:D3:FE:9C:CA:5A:31:6E:BC:81:D3:11:4E:00:90:A3:44:C2 S.fiBefore entering a key into this file, you need to ensure itsauthenticity. How to do this depends on your organisation; youradministrator might have already entered those keys which are deemedtrustworthy enough into this file. Places where to look for thefingerprint of a root certificate are letters received from the CA orthe website of the CA (after making 100% sure that this is indeed thewebsite of that CA). You may want to consider disallowing interactiveupdates of this file by using the [option --no-allow-mark-trusted].It might even be advisable to change the permissions to read-only sothat this file can't be changed inadvertently.As a special feature a line include-default will include a globallist of trusted certificates (e.g. ‘/etc/gnupg/trustlist.txt’).This global list is also used if the local list is not available.It is possible to add further flags after the S for use by thecaller:relax Relax checking of some root certificate requirements. As of now thisflag allows the use of root certificates with a missing basicConstraintsattribute (despite that it is a MUST for CA certificates) and disablesCRL checking for the root certificate.cm If validation of a certificate finally issued by a CA with this flag setfails, try again using the chain validation model.sshcontrolThis file is used when support for the secure shell agent protocol hasbeen enabled (see: [option --enable-ssh-support]). Only keys present inthis file are used in the SSH protocol. You should backup this file.The ssh-add tool may be used to add new entries to this file;you may also add them manually. Comment lines, indicated by a leadinghash mark, as well as empty lines are ignored. An entry starts withoptional whitespace, followed by the keygrip of the key given as 40 hexdigits, optionally followed by the caching TTL in seconds and anotheroptional field for arbitrary flags. A non-zero TTL overrides the globaldefault as set by --default-cache-ttl-ssh.The only flag support is confirm. If this flag is found for akey, each use of the key will pop up a pinentry to confirm the use ofthat key. The flag is automatically set if a new key was loaded intogpg-agent using the option -c of the ssh-addcommand.The keygrip may be prefixed with a ! to disable an entry.The following example lists exactly one key. Note that keys availablethrough a OpenPGP smartcard in the active smartcard reader areimplicitly added to this list; i.e. there is no need to list them.# Key added on: 2011-07-20 20:38:46# Fingerprint: 5e:8d:c4:ad:e7:af:6e:27:8a:d6:13:e4:79:ad:0b:8134B62F25E277CF13D3C6BCEBFD3F85D08F0A864B 0 confirmprivate-keys-v1.d/This is the directory where gpg-agent stores the private keys. Eachkey is stored in a file with the name made up of the keygrip and thesuffix ‘key’. You should backup all files in this directoryand take great care to keep this backup closed away.Note that on larger installations, it is useful to put predefined files into the directory ‘/etc/skel/.gnupg’ so that newly createdusers start up with a working configuration. For existing users the a small helper script is provided to create these files (see:[addgnupghome]).SIGNALSA running gpg-agent may be controlled by signals, i.e. using the kill command to send a signal to the process.Here is a list of supported signals:SIGHUP This signal flushes all cached passphrases and if the program has been started with a configuration file, the configurationfile is read again. Only certain options are honored: quiet, verbose, debug, debug-all, debug-level, debug-pinentry, no-grab,pinentry-program, pinentry-invisible-char, default-cache-ttl, max-cache-ttl, ignore-cache-for-signing, s2k-count, no-allow-external-cache, allow-emacs-pinentry, no-allow-mark-trusted, disable-scdaemon, and disable-check-own-socket. scdaemon-programis also supported but due to the current implementation, which calls the scdaemon only once, it is not of much use unless youmanually kill the scdaemon.SIGTERMShuts down the process but waits until all current requests are fulfilled. If the process has received 3 of these signals andrequests are still pending, a shutdown is forced.SIGINT Shuts down the process immediately.SIGUSR1Dump internal information to the log file.SIGUSR2This signal is used for internal purposes.
gpg-agent --s2k-count ...