Next: , Previous: , Up: Invoking GPG   [Contents][Index]

4.4 Examples

gpg -se -r Bob file

sign and encrypt for user Bob

gpg –clear-sign file

make a cleartext signature

gpg -sb file

make a detached signature

gpg -u 0x12345678 -sb file

make a detached signature with the key 0x12345678

gpg –list-keys user_ID

show keys

gpg –fingerprint user_ID

show fingerprint

gpg –verify pgpfile
gpg –verify sigfile [datafile]

Verify the signature of the file but do not output the data unless requested. The second form is used for detached signatures, where sigfile is the detached signature (either ASCII armored or binary) and datafile are the signed data; if this is not given, the name of the file holding the signed data is constructed by cutting off the extension (".asc" or ".sig") of sigfile or by asking the user for the filename. If the option --output is also used the signed data is written to the file specified by that option; use - to write the signed data to stdout.


The options --import-filter and --export-filter use expressions with this syntax (square brackets indicate an optional part and curly braces a repetition, white space between the elements are allowed):

  [lc] {[{flag}] PROPNAME op VALUE [lc]}

The name of a property (PROPNAME) may only consist of letters, digits and underscores. The description for the filter type describes which properties are defined. If an undefined property is used it evaluates to the empty string. Unless otherwise noted, the VALUE must always be given and may not be the empty string. No quoting is defined for the value, thus the value may not contain the strings && or ||, which are used as logical connection operators. The flag -- can be used to remove this restriction.

Numerical values are computed as long int; standard C notation applies. lc is the logical connection operator; either && for a conjunction or || for a disjunction. A conjunction is assumed at the begin of an expression. Conjunctions have higher precedence than disjunctions. If VALUE starts with one of the characters used in any op a space after the op is required.

The supported operators (op) are:


Substring must match.


Substring must not match.


The full string must match.


The full string must not match.


The numerical value must match.


The numerical value must not match.


The numerical value of the field must be LE than the value.


The numerical value of the field must be LT than the value.


The numerical value of the field must be GT than the value.


The numerical value of the field must be GE than the value.


The string value of the field must be less or equal than the value.


The string value of the field must be less than the value.


The string value of the field must be greater than the value.


The string value of the field must be greater or equal than the value.


True if value is not empty (no value allowed).


True if value is empty (no value allowed).


Alias for "PROPNAME != 0" (no value allowed).


Alias for "PROPNAME == 0" (no value allowed).

Values for flag must be space separated. The supported flags are:

VALUE spans to the end of the expression.


The string match in this part is done case-sensitive.

The filter options concatenate several specifications for a filter of the same type. For example the four options in this example:

 --import-option keep-uid="uid =~ Alfa"
 --import-option keep-uid="&& uid !~ Test"
 --import-option keep-uid="|| uid =~ Alpha"
 --import-option keep-uid="uid !~ Test"

which is equivalent to

 --import-option \
  keep-uid="uid =~ Alfa" && uid !~ Test" || uid =~ Alpha" && "uid !~ Test"

imports only the user ids of a key containing the strings "Alfa" or "Alpha" but not the string "test".


The program returns 0 if everything was fine, 1 if at least a signature was bad, and other error codes for fatal errors.


Use a *good* password for your user account and a *good* passphrase to protect your secret key. This passphrase is the weakest part of the whole system. Programs to do dictionary attacks on your secret keyring are very easy to write and so you should protect your "~/.gnupg/" directory very well.

Keep in mind that, if this program is used over a network (telnet), it is *very* easy to spy out your passphrase!

If you are going to verify detached signatures, make sure that the program knows about it; either give both filenames on the command line or use ‘-’ to specify STDIN.


GnuPG tries to be a very flexible implementation of the OpenPGP standard. In particular, GnuPG implements many of the optional parts of the standard, such as the SHA-512 hash, and the ZLIB and BZIP2 compression algorithms. It is important to be aware that not all OpenPGP programs implement these optional algorithms and that by forcing their use via the --cipher-algo, --digest-algo, --cert-digest-algo, or --compress-algo options in GnuPG, it is possible to create a perfectly valid OpenPGP message, but one that cannot be read by the intended recipient.

There are dozens of variations of OpenPGP programs available, and each supports a slightly different subset of these optional algorithms. For example, until recently, no (unhacked) version of PGP supported the BLOWFISH cipher algorithm. A message using BLOWFISH simply could not be read by a PGP user. By default, GnuPG uses the standard OpenPGP preferences system that will always do the right thing and create messages that are usable by all recipients, regardless of which OpenPGP program they use. Only override this safe default if you really know what you are doing.

If you absolutely must override the safe default, or if the preferences on a given key are invalid for some reason, you are far better off using the --pgp6, --pgp7, or --pgp8 options. These options are safe as they do not force any particular algorithms in violation of OpenPGP, but rather reduce the available algorithms to a "PGP-safe" list.


On older systems this program should be installed as setuid(root). This is necessary to lock memory pages. Locking memory pages prevents the operating system from writing memory pages (which may contain passphrases or other sensitive material) to disk. If you get no warning message about insecure memory your operating system supports locking without being root. The program drops root privileges as soon as locked memory is allocated.

Note also that some systems (especially laptops) have the ability to “suspend to disk” (also known as “safe sleep” or “hibernate”). This writes all memory to disk before going into a low power or even powered off mode. Unless measures are taken in the operating system to protect the saved memory, passphrases or other sensitive material may be recoverable from it later.

Before you report a bug you should first search the mailing list archives for similar problems and second check whether such a bug has already been reported to our bug tracker at .

Next: , Previous: , Up: Invoking GPG   [Contents][Index]