Which Command Is Used To Generate A Gnupg Key
Apr 04, 2017 As others persons can use your public key to send you a message, you can import public from people you trust in to communicate with them. Gpg -import bobpublickey.gpg Conclusion. Now we have notions on the principles to use and generate a public key. You know how GnuPG is functioning and you can use it for secure communication. Apr 04, 2017 It is based on the use of a pair of keys, one public and one private (or secret). Data encrypted with one key can only be decrypted with the other. To encrypt a message to you, someone would use your public key to create a message that could only be unlocked with your private key. The command -generate-key may be used along with the option -batch for unattended key generation. This is the most flexible way of generating keys, but it is also the most complex one. Consider using the quick key manipulation interface described in the previous subsection “The quick key.
- Which Command Is Used To Generate A Gnupg Key Account
- Which Command Is Used To Generate A Gnupg Key Free
- Which Command Is Used To Generate A Gnupg Key Pdf
- Which Command Is Used To Generate A Gnupg Key Download
- Which Command Is Used To Generate A Gnupg Key 2017
I use GPG (also known as GnuPG) software for encrypting files that contain sensitive information (mostly passwords). As a systems engineer, I do most of my work on remote servers, accessible via command line interface. Naturally, I find it easier to use the command line version of GPG to directly encrypt and decrypt documents.
GPG (GNU Privacy Guard) is a free open source version of PGP (Pretty Good Privacy) encryption software. Conceptually, both use the same approach to cryptography (i.e. encryption and decryption). However, each is uniquely different in its implementation.
What follows is a quick primer on how to install the GPG command line tools, as well as a list of basic commands you are most likely to need.
GPG can be installed in a number of different ways. The instructions here will install the core GPG command line tools, which are intended to be used in a terminal.
If, on the other hand, you prefer a graphical user interface (or GUI) for accessing GPG functionality (e.g. encrypting email communications, or encrypting documents in a GUI text editor), refer to the links at the end of this article.
Red Hat / CentOS
Ubuntu / Debian
Mac OS X
The easiest way to install the GPG command line tools on your Mac is to first install Homebrew, a package management system that makes thousands of software packages available for install on your Mac.
Open a Terminal window (Applications > Utilities menu), then enter the following command.
What follows is a very brief introduction to command line usage of GPG. Think of it as a “quick reference” or a “cheat sheet.” You should certainly learn more about GPG than what is explained within this post. It is intended only to get you started. If you expect to use GPG more extensively, I strongly advise you to read more documentation (see the Links section below).
GPG is powerful encryption software, but it can also be easy to learn — once you understand some basics. GPG uses a method of encryption known as public key cryptography, which provides a number of advantages and benefits. However, to obtain these advantages, a minimal level of complexity is required to make it all work. For an overview of how public key cryptography works, read the Introduction to Cryptography (link at the bottom of this post).
Typographical conventions used in commands:
In all examples below, text that you will need to replace with your own values (e.g. usernames, email addresses, filenames) is shown in “gray italic”. Text that you will type literally (unchanged) is indicated with “black constant width”.
Create your GPG key:
To get started with GPG, you first need to generate your key pair. That is, you will generate both a private and a public key with a single command. Enter your name and email address at the prompts, but accept the default options otherwise.
The first key is your private (or secret) key. You must keep this private key safe at all times, and you must not share it with anyone. The private key is protected with a password. Try to make the password as long as possible, but something you will not forget. If you forget the password, there’s no way to recover it. For the same reason, you should also make a backup copy of your private key. (Consider using Time Machine for backups on Mac OS X.)
The second key is your public key, which you can safely share with other people.
The relationship of the private and public key is actually very simple. Anything that is encrypted using the public key can only be decrypted with the related private key. Therefore, you will provide your public key to another person, and they will provide you with their public key. Anything encrypted to your public key can only be decrypted by you. Anything encrypted to the other person’s public key can only be decrypted by the other person.
Export your public key:
The next step is to export your public key and share it with another person. That person should do the same, and export their public key.
Import another person’s public key:
When you import a public key, you are placing it into what is commonly referred to as your GPG “keyring.”
List the public keys in your keyring:
You can now view a list of public keys in your keyring, as well as the name and email address associated with each key.
List private keys in your keyring:
The following command will list the private keys in your keyring. This will show your own private key, which you created earlier.
Trust a public key:
Once you have imported the other person’s public key, you must now set the trust level of the key. This prevents GPG from warning you every time you encrypt something with that public key.
Specify the other person’s name or email in the command.
GPG has many options, most of which you will never need. Here’s a quick list of the most useful commands you are likely to need.
Encrypt a file:
To encrypt a file named filename.txt for a single individual, specify that individual as a recipient.
This will create a new encrypted file named filename.txt.gpg.
If you want to encrypt a file so that only you yourself can decrypt it, then specify yourself as the recipient.
If you want to encrypt a file so that both you and another person can decrypt the file, specify both you and the other person as recipients.
If you want to encrypt a file for a group of people, define the group in your gpg.conf file (see section below), and then specify the group as a recipient.
After a while, you’ll want to be more concise and use the short version of the command line options. Here’s the same command.
Decrypt a file to terminal (standard output):
The first version of this command will display the content of a file within the terminal window itself.
Use the --decrypt
option only if the file is an ASCII text file. If it’s a binary file, then omit the --decrypt
option, which will write the decrypted file to disk. At that point, you can open the binary file in whatever application is used to view the file.
Decrypt a file to disk:
Whether the file is ASCII or binary, if you want to make changes to the content of an encrypted file, you must first decrypt it, make your changes, then re-encrypt the file. As I mentioned in the previous paragraph, you write the decrypted version of a file to disk, by omitting the --decrypt
option from the command.
If the encrypted file was named filename.txt.gpg, the above command will create a decrypted version named filename.txt (with the .gpg extension removed).
Microsoft office standard 2007 key generator. Create Groups of People in Your GPG Configuration File
For convenience, you can pre-define a group of people in your GPG configuration file. This has the benefit of allowing you to encrypt a file to every member of the group by specifying only the group name as the recipient, rather than tediously specifying every individual member of the group. https://iranskiey.weebly.com/blog/best-mac-operating-system-software.
Your GPG software configuration is stored in your home directory within the ~/.gnupg/gpg.conf
file. Edit this file using your favorite command line text editor (vim, nano, pico, emacs, etc). While there are numerous settings available in the configuration file, go to the section pertinent to defining groups.
When defining a group, you list the members of the group. Each member is referenced by some attribute of their public key found in your GPG keyring — typically a person’s name (or partial name, such as first or last name) or an email address (or partial email address).
If you are a member of the group, remember to include yourself in the group! If you do not list yourself in the group, you won’t be able to decrypt any files you encrypt to the group.
Here’s an example of a group named “journalists”, listing the first name of each person.
I encourage you to learn more about GPG. See the Links below.
You may also want to learn about secure methods to erase files from your computer hard drive. Mac OS X has the “Secure Empty Trash” option within Finder. There are also numerous third-party tools you can install.
Since we’re on the theme of learning how to use GPG in the command line, you may want to try “bcwipe” — a program to securely erase files within the command line.
On Mac OS X, you can install bcwipe via Homebrew.
Which Command Is Used To Generate A Gnupg Key Account
General
- Introduction to Cryptography (PDF)
- Homebrew (Package Manager for Mac OS X)
GUI Tools
- GPG Suite (GUI for Mac OS X)
- How To Use GPG Suite on Mac OS X (Electronic Frontier Foundation)
- Gpg4win (GUI for Windows)
- How To Use Gpg4Win on Windows (Electronic Frontier Foundation)
Next: Signing Keys, Previous: Manipulating Keys, Up: Key Management [Contents][Index]
7.5.5 Generating Keys
GPGME provides a set of functions to create public key pairs. Most ofthese functions require the use of GnuPG 2.1 and later; for olderGnuPG versions the gpgme_op_genkey
function can be used.Existing code which wants to update to the new functions or new codewhich shall supports older GnuPG versions may try the new functionsfirst and provide a fallback to the old function if the error codeGPG_ERR_NOT_SUPPORTED
is received.
SINCE: 1.7.0
The function gpgme_op_createkey
generates a new key for theprocotol active in the context ctx. As of now this functiondoes only work for OpenPGP and requires at least version 2.1.13 ofGnuPG.
userid is commonly the mail address associated with the key.GPGME does not require a specific syntax but if more than a mailaddress is given, RFC-822 style format is suggested. The value isexpected to be in UTF-8 encoding (i.e. no IDN encoding for mailaddresses). This is a required parameter.
algo specifies the algorithm for the new key (actually a keypairof public and private key). For a list of supported algorithms, seethe GnuPG manual. If algo is NULL
or the string'default', the key is generated using the default algorithm of theengine. If the string 'future-default' is used the engine may use analgorithm which is planned to be the default in a future release ofthe engine; however existing implementation of the protocol may not beable to already handle such future algorithms. For the OpenPGPprotocol, the specification of a default algorithm, without requestinga non-default usage via flags, triggers the creation of aprimary key plus a secondary key (subkey).
reserved must be set to zero.
expires specifies the expiration time in seconds. If you supply0, a reasonable expiration time is chosen. Use the flagGPGME_CREATE_NOEXPIRE
to create keys that do not expire. Notethat this parameter takes an unsigned long value and not atime_t
to avoid problems on systems which use a signed 32 bittime_t
. Note further that the OpenPGP protocol uses 32 bitvalues for timestamps and thus can only encode dates up to the year2106.
extrakey is currently not used and must be set to NULL
.A future version of GPGME may use this parameter to create X.509 keys.
flags can be set to the bit-wise OR of the following flags:
GPGME_CREATE_SIGN
GPGME_CREATE_ENCR
GPGME_CREATE_CERT
GPGME_CREATE_AUTH
SINCE: 1.7.0
Do not create the key with the default capabilities (key usage) of therequested algorithm but use those explicitly given by these flags:“signing”, “encryption”, “certification”, or “authentication”.The allowed combinations depend on the algorithm.
If any of these flags are set and a default algorithm has beenselected only one key is created in the case of the OpenPGPprotocol.
GPGME_CREATE_NOPASSWD
SINCE: 1.7.0
Request generation of the key without password protection.
GPGME_CREATE_SELFSIGNED
SINCE: 1.7.0
For an X.509 key do not create a CSR but a self-signed certificate.This has not yet been implemented.
GPGME_CREATE_NOSTORE
SINCE: 1.7.0
Do not store the created key in the local key database.This has not yet been implemented.
GPGME_CREATE_WANTPUB
GPGME_CREATE_WANTSEC
SINCE: 1.7.0
Return the public or secret key as part of the result structure.This has not yet been implemented.
GPGME_CREATE_FORCE
SINCE: 1.7.0
The engine does not allow the creation of a key with a user IDalready existing in the local key database. This flag can be used tooverride this check.
GPGME_CREATE_NOEXPIRE
SINCE: 1.8.0
Request generation of keys that do not expire.
After the operation completed successfully, information about thecreated key can be retrieved with gpgme_op_genkey_result
.
The function returns zero on success, GPG_ERR_NOT_SUPPORTED
ifthe engine does not support the command, or a bunch of other errorcodes.
SINCE: 1.7.0
The function gpgme_op_createkey_start
initiates agpgme_op_createkey
operation; see there for details. It mustbe completed by calling gpgme_wait
on the context.See Waiting For Completion.
SINCE: 1.7.0
The function gpgme_op_createsubkey
creates and adds a newsubkey to the primary OpenPGP key given by KEY. The onlyallowed protocol in ctx is GPGME_PROTOCOL_OPENPGP
.Subkeys (aka secondary keys) are a concept in the OpenPGP protocol tobind several keys to a primary key. As of now this function requiresat least version 2.1.13 of GnuPG.
key specifies the key to operate on.
algo specifies the algorithm for the new subkey. For a list ofsupported algorithms, see the GnuPG manual. If algo isNULL
or the string 'default', the subkey is generated using thedefault algorithm for an encryption subkey of the engine. If thestring 'future-default' is used the engine may use an encryptionalgorithm which is planned to be the default in a future release ofthe engine; however existing implementation of the protocol may not beable to already handle such future algorithms.
reserved must be set to zero.
expires specifies the expiration time in seconds. If you supply0, a reasonable expiration time is chosen. Use the flagGPGME_CREATE_NOEXPIRE
to create keys that do not expire. Notethat this parameter takes an unsigned long value and not atime_t
to avoid problems on systems which use a signed 32 bittime_t
. Note further that the OpenPGP protocol uses 32 bitvalues for timestamps and thus can only encode dates up to the year2106.
Which Command Is Used To Generate A Gnupg Key Free
flags takes the same values as described above forgpgme_op_createkey
.
After the operation completed successfully, information about thecreated key can be retrieved with gpgme_op_genkey_result
.
The function returns zero on success, GPG_ERR_NOT_SUPPORTED
ifthe engine does not support the command, or a bunch of other errorcodes.
SINCE: 1.7.0
The function gpgme_op_createsubkey_start
initiates agpgme_op_createsubkey
operation; see there for details. It mustbe completed by calling gpgme_wait
on the context.See Waiting For Completion.
SINCE: 1.7.0
The function gpgme_op_adduid
adds a new user ID to the OpenPGPkey given by KEY. Adding additional user IDs after key creationis a feature of the OpenPGP protocol and thus the protocol for thecontext ctx must be set to OpenPGP. As of now this functionrequires at least version 2.1.13 of GnuPG.
key specifies the key to operate on.
userid is the user ID to add to the key. A user ID is commonlythe mail address to be associated with the key. GPGME does notrequire a specific syntax but if more than a mail address is given,RFC-822 style format is suggested. The value is expected to be inUTF-8 encoding (i.e. no IDN encoding for mail addresses). This is arequired parameter.
flags are currently not used and must be set to zero.
The function returns zero on success, GPG_ERR_NOT_SUPPORTED
ifthe engine does not support the command, or a bunch of other errorcodes.
SINCE: 1.7.0
The function gpgme_op_adduid_start
initiates agpgme_op_adduid
operation; see there for details. It mustbe completed by calling gpgme_wait
on the context.See Waiting For Completion.
SINCE: 1.7.0
The function gpgme_op_revuid
revokes a user ID from the OpenPGPkey given by KEY. Revoking user IDs after key creation is afeature of the OpenPGP protocol and thus the protocol for the contextctx must be set to OpenPGP. As of now this function requires atleast version 2.1.13 of GnuPG.
key specifies the key to operate on.
userid is the user ID to be revoked from the key. The user IDmust be given verbatim because the engine does an exact and casesensitive match. Thus the uid
field from the user ID object(gpgme_user_id_t
) is to be used. This is a required parameter.
flags are currently not used and must be set to zero.
Note that the engine won’t allow to revoke the last valid user ID. Tochange a user ID is better to first add the new user ID, then revokethe old one, and finally publish the key.
The function returns zero on success, GPG_ERR_NOT_SUPPORTED
ifthe engine does not support the command, or a bunch of other errorcodes.
SINCE: 1.7.0
The function gpgme_op_revuid_start
initiates agpgme_op_revuid
operation; see there for details. It mustbe completed by calling gpgme_wait
on the context.See Waiting For Completion.
SINCE: 1.8.0
The function gpgme_op_set_uid_flag
is used to set flags on auser ID from the OpenPGP key given by KEY. Setting flags onuser IDs after key creation is a feature of the OpenPGP protocol andthus the protocol for the context ctx must be set to OpenPGP.
key specifies the key to operate on. This parameters is required.
userid is the user ID of the key to be manipulated. This user IDmust be given verbatim because the engine does an exact and casesensitive match. Thus the uid
field from the user ID object(gpgme_user_id_t
) is to be used. This is a required parameter.
name names the flag which is to be changed. The only currentlysupported flag is:
primary
This sets the primary key flag on the given user ID. All otherprimary key flag on other user IDs are removed. value must begiven as NULL. For technical reasons this functions bumps thecreation timestamp of all affected self-signatures up by one second.At least GnuPG version 2.1.20 is required.
The function returns zero on success, GPG_ERR_NOT_SUPPORTED
ifthe engine does not support the command, or a bunch of other errorcodes.
SINCE: 1.8.0
The function gpgme_op_set_uid_flag_start
initiates agpgme_op_set_uid_flag
operation; see there for details. It mustbe completed by calling gpgme_wait
on the context.See Waiting For Completion.
The function gpgme_op_genkey
generates a new key pair in thecontext ctx. The meaning of public and secretdepends on the crypto backend.
GPG does not support public and secret, they should beNULL
. GnuPG will generate a key pair and add it to thestandard key ring. The fingerprint of the generated key is availablewith gpgme_op_genkey_result
.
GpgSM requires public to be a writable data object. GpgSM willgenerate a secret key (which will be stored by gpg-agent
,and return a certificate request in public, which then needs tobe signed by the certification authority and imported before it can beused. GpgSM does not make the fingerprint available.
The argument parms specifies parameters for the key in an stringthat looks something like XML. The details about the format ofparms are specific to the crypto engine used by ctx. Thefirst line of the parameters must be <GnupgKeyParamsformat='internal'>
and the last line must be</GnupgKeyParams>
. Every line in between the first and lastlines is treated as a Header: Value pair. In particular, no XMLescaping is necessary if you need to include the characters <
,>
, or &
.
Here is an example for GnuPG as the crypto engine (all parameters ofOpenPGP key generation are documented in the GPG manual):
Here is an example for GpgSM as the crypto engine (all parameters ofOpenPGP key generation are documented in the GPGSM manual):
Strings should be given in UTF-8 encoding. The only format supportedfor now is “internal”. The content of the GnupgKeyParms
container is passed verbatim to the crypto backend. Controlstatements are not allowed.
/godaddy-generate-ssl-private-key.html. After the operation completed successfully, the result can beretrieved with gpgme_op_genkey_result
.
The function returns the error code GPG_ERR_NO_ERROR
if theoperation could be started successfully, GPG_ERR_INV_VALUE
ifparms is not a well-formed string (e.g. does not have theexpected tag-like headers and footers), GPG_ERR_NOT_SUPPORTED
if public or secret is not valid, andGPG_ERR_GENERAL
if no key was created by the backend.
The function gpgme_op_genkey_start
initiates agpgme_op_genkey
operation. It can be completed by callinggpgme_wait
on the context. See Waiting For Completion.
The function returns the error code GPG_ERR_NO_ERROR
if theoperation could be started successfully, GPG_ERR_INV_VALUE
ifparms is not a valid XML string, andGPG_ERR_NOT_SUPPORTED
if public or secret is notNULL
.
This is a pointer to a structure used to store the result of agpgme_op_genkey
operation. After successfully generating akey, you can retrieve the pointer to the result withgpgme_op_genkey_result
. The structure contains the followingmembers:
unsigned int primary : 1
This flag is set to 1 if a primary key was created and to 0if not.
unsigned int sub : 1
This flag is set to 1 if a subkey was created and to 0 if not.
unsigned int uid : 1
Which Command Is Used To Generate A Gnupg Key Pdf
This flag is set to 1 if a user ID was created and to 0 if not.
char *fpr
This is the fingerprint of the key that was created. If both aprimary and a subkey were generated, the fingerprint of the primarykey will be returned. If the crypto engine does not provide thefingerprint, fpr
will be a null pointer.
gpgme_data_t pubkey
SINCE: 1.7.0
Which Command Is Used To Generate A Gnupg Key Download
This will eventually be used to return the public key. It iscurrently not used.
gpgme_data_t seckey
SINCE: 1.7.0
This will eventually be used to return the secret key. It iscurrently not used.
The function gpgme_op_genkey_result
returns agpgme_genkey_result_t
pointer to a structure holding the result ofa gpgme_op_genkey
operation. The pointer is only valid if thelast operation on the context was a gpgme_op_genkey
orgpgme_op_genkey_start
operation, and if this operation finishedsuccessfully. The returned pointer is only valid until the nextoperation is started on the context.
Which Command Is Used To Generate A Gnupg Key 2017
Next: Signing Keys, Previous: Manipulating Keys, Up: Key Management [Contents][Index]