gpg-agent
Secret key management for GnuPG
- Provided by: gpg-agent (Version: 2.2.4-1ubuntu1.6)
- Source: gnupg2
- Report a bug
Secret key management for GnuPG
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]
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. Thus there is no reason to start it manually. In case you want to use the included Secure Shell Agent you may start the agent using:
gpg-connect-agent /bye
If you want to manually terminate the currently-running agent, you can safely do so with:
gpgconf --kill gpg-agent
You should always add the following lines to your .bashrc or whatever initialization file is used for all shell invocations:
GPG_TTY=$(tty) export GPG_TTY
It is important that this environment variable always reflects the output of the tty command. For W32 systems this option is not required.
Please make sure that a proper pinentry program has been installed under the default filename (which is system dependent) or use the option pinentry-program to specify the full name of that program. It is often useful to install a symbolic link from the actual used pinentry (e.g. ‘/usr/bin/pinentry-gtk’) to the expected one (e.g. ‘/usr/bin/pinentry’).
Commands are not distinguished from options except for the fact that only one command is allowed.
As an alternative you may create a new process as a child of gpg-agent: gpg-agent --daemon /bin/sh. This way you get a new shell with the environment setup properly; after you exit from this shell, gpg-agent terminates within a few seconds.
In --supervised mode, different file descriptors can be provided for use as different socket types (e.g. ssh, extra) as long as they are identified in the environment variable LISTEN_FDNAMES (see sd_listen_fds(3) on some Linux distributions for more information on this convention).
Options may either be used on the command line or, after stripping off the two leading dashes, in the configuration file.
On Windows systems it is possible to install GnuPG as a portable application. In this case only this command line option is considered, 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 as the tool ‘gpgconf.exe’. The root of the installation is then that directory; or, if ‘gpgconf.exe’ has been installed directly below a directory named ‘bin’, its parent directory. You also need to make sure that the following directories exist and are writable: ‘ROOT/home’ for the GnuPG home and ‘ROOT/var/cache/gnupg’ for internal cache files.
How these messages are mapped to the actual debugging flags is not specified and may change with newer releases of this program. They are however carefully selected to best aid in debugging.
On GNU/Linux, another way to quickly generate insecure keys is to use rngd to fill the kernel's entropy pool with lower quality random data. rngd is typically provided by the rng-tools package. It can be run as follows: 'sudo rngd -f -r /dev/urandom'.
The --force option of the Assuan command DELETE_KEY is also controlled by this option: The option is ignored if a loopback pinentry is disallowed.
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.
Security note: It is known that checking a passphrase against a list of pattern or even against a complete dictionary is not very effective to enforce good passphrases. Users will soon figure up ways to bypass such a policy. A better policy is to educate users on good security behavior and optionally to run a passphrase cracker regularly on all users passphrases to catch the very simple ones.
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\pinentry-basic.exe’ where the file names are relative to the GnuPG installation directory.
Also listen on native gpg-agent connections on the given socket. The intended use for this extra socket is to setup a Unix domain socket forwarding from a remote machine to this socket on the local machine. A gpg running on the remote machine may then connect to the local gpg-agent and use its private keys. This enables decrypting or signing data on a remote machine without exposing the private keys to the remote machine.
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 by OpenSSH (through a separate socket). Consequently, it should be possible to use the gpg-agent as a drop-in replacement for the 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 the agent; this causes the gpg-agent to ask for a passphrase, which is to be used for encrypting the newly received key and storing 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 necessary for decrypting the stored key. Since the ssh-agent protocol does not contain a mechanism for telling the agent on which display/terminal it is running, gpg-agent's ssh-support will use the TTY or X display where gpg-agent has been started. To switch this display to the current one, the following command may be used:
gpg-connect-agent updatestartuptty /bye
Although all GnuPG components try to start the gpg-agent as needed, this is not possible for the ssh support because ssh does not know 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-agent for authentication. To fix this you may start gpg-agent if needed using this simple command:
gpg-connect-agent /bye
Adding 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. This is similar to the regular ssh-agent support but makes use of Windows message queue as required by putty.
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.
To view the actually used iteration count and the milliseconds required for an S2K operation use:
gpg-connect-agent 'GETINFO s2k_count' /bye gpg-connect-agent 'GETINFO s2k_time' /bye
To view the auto-calibrated count use:
gpg-connect-agent 'GETINFO s2k_count_cal' /bye
It 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_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
There are a few configuration files needed for the operation of the agent. By default they may all be found in the current home directory (see: [option --homedir]).
Comment lines, indicated by a leading hash mark, as well as empty
lines are ignored. To mark a key as trusted you need to enter its
fingerprint followed by a space and a capital letter S. Colons
may optionally be used to separate the bytes of a fingerprint; this
enables cutting and pasting the fingerprint from a key listing output. If
the line is prefixed with a ! the key is explicitly marked as
not trusted.
Here is an example where two keys are marked as ultimately trusted
and one as not trusted:
.RS 2
# CN=Wurzel ZS 3,O=Intevation GmbH,C=DE A6935DD34EF3087973C706FC311AA2CCF733765B S # CN=PCA-1-Verwaltung-02/O=PKI-1-Verwaltung/C=DE DC: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 .fi
Before entering a key into this file, you need to ensure its authenticity. How to do this depends on your organisation; your administrator might have already entered those keys which are deemed trustworthy enough into this file. Places where to look for the fingerprint of a root certificate are letters received from the CA or the website of the CA (after making 100% sure that this is indeed the website of that CA). You may want to consider disallowing interactive updates of this file by using the [option --no-allow-mark-trusted]. It might even be advisable to change the permissions to read-only so that this file can't be changed inadvertently. As a special feature a line include-default will include a global list 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 the caller:
Relax checking of some root certificate requirements. As of now this
flag allows the use of root certificates with a missing basicConstraints
attribute (despite that it is a MUST for CA certificates) and disables
CRL checking for the root certificate.
If validation of a certificate finally issued by a CA with this flag set
fails, try again using the chain validation model.
This file is used when support for the secure shell agent protocol has
been enabled (see: [option --enable-ssh-support]). Only keys present in
this 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 leading
hash mark, as well as empty lines are ignored. An entry starts with
optional whitespace, followed by the keygrip of the key given as 40 hex
digits, optionally followed by the caching TTL in seconds and another
optional field for arbitrary flags. A non-zero TTL overrides the global
default as set by --default-cache-ttl-ssh.
The only flag support is confirm. If this flag is found for a
key, each use of the key will pop up a pinentry to confirm the use of
that key. The flag is automatically set if a new key was loaded into
gpg-agent using the option -c of the ssh-add
command.
The keygrip may be prefixed with a ! to disable an entry.
The following example lists exactly one key. Note that keys available
through a OpenPGP smartcard in the active smartcard reader are
implicitly 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:81 34B62F25E277CF13D3C6BCEBFD3F85D08F0A864B 0 confirm
This is the directory where gpg-agent stores the private keys. Each
key is stored in a file with the name made up of the keygrip and the
suffix ‘key’. You should backup all files in this
directory
and 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 created users start up with a working configuration. For existing users the a small helper script is provided to create these files (see: [addgnupghome]).
A 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:
gpg(1), gpgsm(1), gpgconf(1), gpg-connect-agent(1), scdaemon(1)
The full documentation for this tool is maintained as a Texinfo manual. If GnuPG and the info program are properly installed at your site, the command
info gnupg
should give you access to the complete manual including a menu structure and an index.