GNU gpg is encryption and signing tool.
The GNU Privacy Guard (GnuPG or GPG) is a free software replacement for the PGP suite of cryptographic software.
Jun 30, 2018 Create Your Public/Private Key Pair and Revocation Certificate. Use gpg -full-gen-key command to generate your key pair. Gpg -full-gen-key. It asks you what kind of key you want. Notice there’re four options. The default is to create a RSA public/private key pair and also a RSA signing key. Let’s hit Enter to select the default. I am going to add a feature in my own version of SSPKS to sign Synology packages. But to do this, I need a way to create GPG key from a non-interactive script. Click to Read More.
GnuPG encrypts messages using asymmetric keypairs individually generated by GnuPG users. The resulting public keys can be exchanged with other users in a variety of ways, such as Internet key servers. They must always be exchanged carefully to prevent identity spoofing by corrupting public key ↔ ‘owner’ identity correspondences. It is also possible to add a cryptographic digital signature to a message, so the message integrity and sender can be verified, if a particular correspondence relied upon has not been corrupted.
1) Login to your shell account
2) Use gpg command to create the keys$ gpg --gen-key
Output:
3) Now keys generated, you can list your own key using:$ gpg -K
OR$ gpg --list-keys
Output:
Let us try to understand the line pub 1024D/CA7A8402 2007-02-10:
Most important is the key ID i.e. CA7A8402. Make sure you use powerful passphrase to protect keys and not the easy one.
4) To list secret key, type the command:$ gpg --list-secret-keys
Output:
ADVERTISEMENTS
This is a very old version of the gpg man page. Please see the latestrelease or software package for your operating system to find an up todate version ('man gpg2').
gpg is the main program for the GnuPG system.
This man page does only list the commands and options available. For amore verbose documentation get the GNU Privacy Handbook (GPH), which isavailable at https://www.gnupg.org/gph/ . You will find a list of HOWTOdocuments at https://www.gnupg.org/docs.html .
gpg recognizes these commands:
Make a signature. This command may be combined with--encrypt.
Make a clear text signature.
Make a detached signature.
Encrypt data. This option may be combined with--sign.
Encrypt with symmetric cipher only This commandasks for a passphrase.
Store only (make a simple RFC1991 packet).
file
]Decrypt file
(or stdin if no file isspecified) and write it to stdout (or the file specified with--output). If the decrypted file is signed, the signature is alsoverified. This command differs from the default operation, as itnever writes to the filename which is included in the file and itrejects files which don't begin with an encrypted message.
sigfile
] [ signed-files
]]Assume that sigfile
is asignature and verify it without generating any output. With noarguments, the signature packet is read from stdin (it may be adetached signature when not used in batch mode). If only a sigfile isgiven, it may be a complete signature or a detached signature, inwhich case the signed stuff is expected in a file without the '.sig'or '.asc' extension (if such a file does not exist it is expected atstdin; use a single dash ('-') as filename to force a read fromstdin). With more than 1 argument, the first should be a detachedsignature and the remaining files are the signed stuff.
files
]This is a special version of the --verifycommand which does not work with detached signatures. The commandexpects the files to bee verified either on the commandline or readsthe filenames from stdin; each anem muts be on separate line. Thecommand is intended for quick checking of many files.
names
], --list-public-keys [ names
]List all keysfrom the public keyrings, or just the ones given on the command line.
names
]List all keys from the secretkeyrings, or just the ones given on the command line.
names
]Same as --list-keys, but the signatures arelisted too.
names
]Same as --list-sigs, but the signatures areverified.
names
]List all keys with their fingerprints.This is the same output as --list-keys but with the additional outputof a line with the fingerprint. May also be combined with --list-sigsor --check-sigs. If this command is given twice, the fingerprints ofall secondary keys are listed too.
List only the sequence of packets. This is mainlyuseful for debugging.
Generate a new key pair. This command is normally onlyused interactive.
There is an experimental feature which allows to create keys in batchmode. See the file doc/DETAILS
in the source distribution on how touse this.
name
Present a menu which enables you to do all keyrelated tasks:
name
If the key is notyet signed by the default user (or the users given with -u), theprogram displays the information of the key again, together withits fingerprint and asks whether it should be signed. Thisquestion is repeated for all users specified with -u.n
n
. Use 0 todeselect all.n
n
. Use 0 todeselect all.The listing shows you the key with its secondary keys and all userids. Selected keys or user ids are indicated by an asterisk. Thetrust value is displayed with the primary key: the first is theassigned owner trust and the second is the calculated trust value.Letters are used for the values:
name
Sign a public key with you secret key. This is ashortcut version of the subcommand 'sign' from --edit.
name
Sign a public key with you secret key but markit as non-exportable. This is a shortcut version of the subcommand'lsign' from --edit.
long key ID
Assume that the specified key (whichmust be given as a full 8 byte key ID) is as trustworthy as one ofyour own secret keys. This option is useful if you don't want to keepyour secret keys (or one of them) online but still be able to checkthe validity of a given recipient's or signator's key.
name
Remove key from the public keyring
name
Remove key from the secret and publickeyring
Generate a revocation certificate for the completekey. To revoke a subkey or a signature, use the --edit command.
names
]Either export all keys from all keyrings(default keyrings and those registered via option --keyring), or ifat least one name is given, those of the given name. The new keyringis written to stdout or to the file given with option 'output'. Usetogether with --armor to mail those keys.
names
]Same as --export but sends the keys to akeyserver. Option --keyserver must be used to give the name of thiskeyserver. Don't send your complete keyring to a keyserver - selectonly those keys which are new or changed by you.
names
]Same as --export, but does also export keyswhich are not compatible to OpenPGP.
--export-secret-keys [ names
], --export-secret-subkeys[ names
] :: Same as --export, but does export the secret keys. Thisis normally not very useful and a security risk. the second form ofthe command has the special property to render the secret part of theprimary key useless; this is a GNU extension to OpenPGP and otherimplementations can not be expected to successful import such a key.
files
], --fast-import [ files
]Import/merge keys.This adds the given keys to the keyring. The fast version does notbuild the trustdb; this can be done at any time with the command--update-trustdb.
There are a few other options which control how this command works.Most notable here is the --merge-only options which does not insertnew keys but does only the merging of new signatures, user-IDs andsubkeys.
key IDs
Import the keys with the given key IDs froma HKP keyserver. Option --keyserver must be used to give the name ofthis keyserver.
List the assigned ownertrust values in ASCIIformat for backup purposes
files
]Update the trustdb with theownertrust values stored in files
(or stdin if not given); existingvalues will be overwritten.
algo
[ files
]Print message digest of algorithm ALGOfor all given files of stdin. If '*' is used for the algorithm,digests for all available algorithms are printed.
0 1 2
[ count
]Emit COUNT random bytes of thegiven quality level. If count is not given or zero, an endlesssequence of random bytes will be emitted. PLEASE, don't use thiscommand unless you know what you are doing, it may remove preciousentropy from the system!
mode
bits
[ qbits
]Use the source, Luke :-). Theoutput format is still subject to change.
Print version information along with a list of supportedalgorithms.
Print warranty information.
Print usage information. This is a really long listeven it does list not all options.
Long options can be put in an options file (default '~/.gnupg/options').Do not write the 2 dashes, but simply the name of the option and anyrequired arguments. Lines with a hash as the first non-white-spacecharacter are ignored. Commands may be put in this file too, but thatdoes not make sense.
gpg recognizes these options:
Create ASCII armored output.
file
Write output to file
.
name
Use name
as the user ID to sign. Thisoption is silently ignored for the list commands, so that it can beused in an options file.
name
Use name
as default user ID for signatures.If this is not used the default user ID is the first user ID found inthe secret keyring.
name
, Encrypt for user id name
. If thisoption is not specified, GnuPG asks for the user-id unless--default-recipient is given
name
Use name
as default recipient ifoption --recipient is not used and don't ask if this is a valid one.name
must be a non empty.
Use the default key as default recipientif option --recipient is not used and don't ask if this is a validone. The default key is the first one from the secret keyring or theone set with --default-key.
Reset --default-recipient and--default-recipient-self.
name
Same as --recipient but this one is intendedfor in the options file and may be used together with an own user-idas an 'encrypt-to-self'. These keys are only used when there areother recipients given either by use of --recipient or by the askeduser id. No trust checking is performed for these user ids and evendisabled keys can be used.
Disable the use of all --encrypt-to keys.
Give more information during processing. If usedtwice, the input data is listed in detail.
Try to be as quiet as possible.
n
Set compression level to n
. A value of 0 for n
disablescompression. Default is to use the default compression level of zlib(normally 6).
Use canonical text mode. If -t (but not --textmode)is used together with armoring and signing, this enables clearsignedmessages. This kludge is needed for PGP compatibility; normally youwould use --sign or --clearsign to selected the type of thesignature.
Don't make any changes (this is not completelyimplemented).
Prompt before overwriting any files.
Use batch mode. Free software key generator. Never ask, do not allow interactivecommands.
Make sure that the TTY (terminal) is never used for anyoutput. This option is needed in some cases because GnuPG sometimesprints warnings to the TTY if if --batch is used.
Disable batch mode. This may be of use if --batch isenabled from an options file.
Assume 'yes' on most questions.
Assume 'no' on most questions.
Skip key validation and assume that used keys arealways fully trusted. You won't use this unless you have installedsome external validation scheme.
name
Use name
to lookup keys which are not yet inyour keyring. This is only done while verifying messages withsignatures. The option is also required for the command --send-keysto specify the keyserver to where the keys should be send. Allkeyservers synchronize with each other - so there is no need to sendkeys to more than one server. Using the command 'host -l pgp.net grep wwwkeys' gives you a list of keyservers. Because there is loadbalancing using round-robin DNS you may notice that you get differentkey servers.
This option disables the automaticretrieving of keys from a keyserver while verifying signatures. Thisoption allows to keep a keyserver in the options file or the--send-keys and --recv-keys commands.
Try to access the keyserver over the proxy setwith the variable 'httpproxy'.
file
Add file
to the list of keyrings. If file
begins with a tilde and a slash, these are replaced by the HOMEdirectory. If the filename does not contain a slash, it is assumed tobe in the home-directory ('~/.gnupg' if --homedir is not used). Thefilename may be prefixed with a scheme:
'gnupg-ring:' is the default one.
'gnupg-gdbm:' may be used for a GDBM ring. Note that GDBM isexperimental and likely to be removed in future versions.
It might make sense to use it together with --no-default-keyring.
file
Same as --keyring but for the secretkeyrings.
directory
Set the name of the home directory todirectory
If this option is not used it defaults to '~/.gnupg'. Itdoes not make sense to use this in a options file. This alsooverrides the environment variable 'GNUPGHOME'.
name
Set the name of the native character set. This isused to convert some strings to proper UTF-8 encoding. Valid valuesfor name
are:
Assume that the arguments arealready given as UTF8 strings. The default (--no-utf8-strings) is toassume that arguments are encoded in the character set as specifiedby --charset. These options effects all following arguments. Bothoptions may used multiple times.
file
Php defuse crypto generate encryption key. Read options from file
and do not try to readthem from the default options file in the homedir (see --homedir).This option is ignored if used in an options file.
Shortcut for '--options /dev/null'. This option isdetected before an attempt to open an option file.
name
Load an extension module. If name
doesnot contain a slash it is searched in '/usr/local/lib/gnupg' See themanual for more information about extensions.
flags
Set debugging flags. All flags are or-ed andflags
may be given in C syntax (e.g. 0x0042).
Set all useful debugging flags.
n
Write special status strings to the filedescriptor n
. See the file DETAILS in the documentation for alisting of them.
n
Write log output to file descriptor n
and not tostderr.
Do not write comment packets. This option affectsonly the generation of secret keys. Please note, that this hasnothing to do with the comments in clear text signatures.
string
Use string
as comment string in clear textsignatures. To suppress those comment strings entirely, use an emptystring here.
Force to write the standard comment string inclear text signatures. Use this to overwrite a --comment from aconfig file.
Omit the version string in clear text signatures.
Force to write the version string in clear textsignatures. Use this to overwrite a previous --no-version from aconfig file.
name=value
Put the name value pair into thesignature as notation data. name
must consists only of alphanumericcharacters, digits or the underscore; the first character must not bea digit. value
may be any printable string; it will encoded inUTF8, so sou should have check that your --charset is set right. Ifyou prefix name
with an exclamation mark, the notation data will beflagged as critical (rfc2440:5.2.3.15).
string
Use string
as Policy URL forsignatures (rfc2440:5.2.3.19). If you prefix it with an exclamationmark, the policy URL packet will be flagged as critical.
string
Use string
as the name of file which isstored in messages.
Try to create a file with a name asembedded in the data. This can be a dangerous option as it allows tooverwrite files.
n
Number of completely trusted users tointroduce a new key signer (defaults to 1).
n
Number of marginally trusted users tointroduce a new key signer (defaults to 3)
n
Maximum depth of a certification chain(default is 5).
name
Use name
as cipher algorithm. Running theprogram with the command --version yields a list of supportedalgorithms. If this is not used the cipher algorithm is selected fromthe preferences stored with the key.
name
Use name
as message digest algorithm.Running the program with the command --version yields a list ofsupported algorithms. Please note that using this option may violatethe OpenPGP requirement, that a 160 bit hash is to be used for DSA.
name
Use name
as the cipher algorithm usedto protect secret keys. The default cipher is BLOWFISH. This cipheris also used for conventional encryption if --cipher-algo is notgiven.
name
Use name
as the digest algorithm usedto mangle the passphrases. The default algorithm is RIPE-MD-160. Thisdigest algorithm is also used for conventional encryption if--digest-algo is not given.
n
Selects how passphrases are mangled. If n
is 0 aplain passphrase (which is not recommended) will be used, a 1(default) adds a salt to the passphrase and a 3 iterates the wholeprocess a couple of times. Unless --rfc1991 is used, this mode isalso used for conventional encryption.
n
Use compress algorithm n
. Default is 2 whichis RFC1950 compression. You may use 1 to use the old zlib version(RFC1951) which is used by PGP. The default algorithm may give betterresults because the window size is not limited to 8K. If this is notused the OpenPGP behavior is used, i.e. the compression algorithm isselected from the preferences; note, that this can't be done if youdo not encrypt the data.
name
Never allow the use of name
ascipher algorithm. The given name will not be checked so that a laterloaded algorithm will still get disabled.
name
Never allow the use of name
aspublic key algorithm. The given name will not be checked so that alater loaded algorithm will still get disabled.
Do not put the keyid into encrypted packets. Thisoption hides the receiver of the message and is a countermeasureagainst traffic analysis. It may slow down the decryption processbecause all available secret keys are tried.
This option changes the behavior of cleartextsignatures so that they can be used for patch files. You should notsend such an armored file via email because all spaces and lineendings are hashed too. You can not use this option for data whichhas 5 dashes at the beginning of a line, patch files don't have this.A special armor header line tells GnuPG about this cleartextsignature option.
Because some mailers change lines startingwith 'From ' to '<From ' it is good to handle such lines in a specialway when creating cleartext signatures. All other PGP versions do itthis way too. This option is not enabled by default because it wouldviolate rfc2440.
n
Read the passphrase from file descriptor n
.If you use 0 for n
, the passphrase will be read from stdin. Thiscan only be used if only one passphrase is supplied. Don't use thisoption if you can avoid it.
n
This is a replacement for the depreciatedshared-memory IPC mode. If this option is enabled, user input onquestions is not expected from the TTY but from the given filedescriptor. It should be used together with --status-fd. See the filedoc/DETAILS in the source distribution for details on how to use it.
Try to be more RFC1991 (PGP 2.x) compliant.
Reset all packet, cipher and digest options to OpenPGPbehavior. Use this option to reset all previous options like--rfc1991, --force-v3-sigs, --s2k-*, --cipher-algo, --digest-algo and--compress-algo to OpenPGP compliant values. All PGP workarounds arealso disabled.
OpenPGP states that an implementation shouldgenerate v4 signatures but PGP 5.x recognizes v4 signatures only onkey material. This options forces v3 signatures for signatures ondata.
Force the use of encryption with appended manipulationcode. This is always used with the newer cipher (those with ablocksize greater than 64 bit). This option might not be implementedyet.
Allow the import of keys with user IDswhich are not self-signed. This is only allows the import - keyvalidation will fail and you have to check the validity of the key myother means. This hack is needed for some German keys generated withpgp 2.6.3in. You should really avoid using it, because OpenPGP hasbetter mechanics to do separate signing and encryption keys.
Disable all checks on the form of the user IDwhile generating a new one. This option should only be used in veryspecial environments as it does not ensure the de-facto standardformat of user IDs.
GnuPG normally checks that the timestampsassociated with keys and signatures have plausible values. However,sometimes a signature seems to be older than the key due to clockproblems. This option makes these checks just a warning.
Lock the databases the first time a lock is requestedand do not release the lock until the process terminates.
Release the locks every time a lock is no longerneeded. Use this to override a previous --lock-once from a configfile.
Disable locking entirely. This option should be usedonly in very special environments, where it can be assured that onlyone process is accessing those files. A bootable floppy with astandalone encryption system will probably use this. Improper usageof this option may lead to data and key corruption.
GnuPG uses a file to store it's internalrandom pool over invocations. This makes random generation faster;however sometimes write operations are not desired. This option canbe used to achive that with the cost of slower random generation.
Reset verbose level to 0.
Suppress the initial copyright message but do notenter batch mode.
Suppress the warning about 'using insecurememory'.
Assume the input data is not in ASCII armored format.
Do not add the default keyrings to the listof keyrings.
Skip the signature verification step. This may beused to make the decryption faster if the signature verification isnot needed.
Print key listings delimited by colons.
Print key listings delimited by colons and printthe public key data.
Same as the command --fingerprint but changesonly the format of the output and may be used together with anothercommand.
Changes the output of the list commands to workfaster; this is achieved by leaving some parts empty. Someapplications don't need the user ID and the trust information givenin the listings. By using this options they can get a faster listing.The excact behaviour of this option may change in future versions.
Changes the behaviour of some commands. This is like--dry-run but different in some cases. The semantic of this commandmay be extended in the future. Currently it does only skip the actualdecryption pass and therefore enables a fast listing of theencryption keys.
This is not for normal use. Use the source to see forwhat it might be useful.
This is not for normal use. Use the source to seefor what it might be useful.
GnuPG versions prior to 1.0.2 had a bug inthe way a signature was encode. This options enables a workaround bychecking faulty signatures again with the encoding used in oldversions. This may only happen for ElGamal signatures which are notwidely used.
Display the session key used for one message.See --override-session-key for the counterpart of this option.
We think that Key-Escrow is a Bad Thing; however the user should havethe freedom to decide whether to go to prison or to reveal thecontent of one specific message without compromising all messagesever encrypted for one secret key. DON'T USE IT UNLESS YOU ARE REALLYFORCED TO DO SO.
string
Don't use the public key but thesession key string
. The format of this string is the same as theone printed by --show-session-key. This option is normally not usedbut comes handy in case someone forces you to reveal the content ofan encrypted message; using this option you can do this withouthanding out the secret key.
Don't insert new keys into the keyrings while doingan import.
Don't look at the key ID as stored in themessage but try all secret keys in turn to find the right decryptionkey. This option forces the behaviour as used by anonymous recipients(created by using --throw-keyid) and might come handy in case wherean encrypted message contains a bogus key ID.
There are different ways on how to specify a user ID to GnuPG; here aresome examples:
The program returns 0 if everything was fine, 1 if at least a signaturewas bad, and other error codes for fatal errors.
Bob
file
file
file
user_ID
user_ID
pgpfile
, gpg --verify sigfile
[ files
]sigfile
is the detachedsignature (either ASCII armored of binary) and [ files
] are thesigned data; if this is not given the name of the file holding thesigned data is constructed by cutting off the extension ('.asc' or'.sig') of sigfile
or by asking the user for the filename.Use a good password for your user account and a good passphrase toprotect your secret key. This passphrase is the weakest part of thewhole system. Programs to do dictionary attacks on your secret keyringare 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), itis very easy to spy out your passphrase!
On many systems this program should be installed as setuid(root). Thisis necessary to lock memory pages. Locking memory pages prevents theoperating system from writing memory pages to disk. If you get nowarning message about insecure memory 3our operating system supportslocking without being root. The program drops root privileges as soon aslocked memory is allocated.