How to export and import keys with GPG
To encrypt electronic mail and information, you wish to have to know the way to generate, export, and import GPG keys. For example, you’ve got generated a GPG key pair by means of the usage of the “gpg –gen-key” command, and now you wish to have to export your private and non-private keys to switch in conversation. With the assistance of the “gpg” command, you’ll be able to simply export and import the general public key and personal key. However, in terms of the personal key, a passphrase shall be related to the exported document that can be used to import that particular personal key in a secret keyring.
This write-up will information you in exporting and uploading private and non-private keys with GPG. Moreover, a realistic instance shall be supplied to turn you the process of exporting and uploading GPG keys between two methods. So, let’s get started!
Types of GPG keys
The GPG key pair incorporates two forms of keys: Private and Public keys. The personal GPG keys are encrypted and saved in the name of the game keyring, and public keys are maintained with certificate testifying to their trustworthiness within the public keyring. You can use the general public key for the knowledge encryption, and that encrypted information shall be decrypted the usage of the Private key. Anyone can use your public key to encrypt the knowledge; on the other hand, the personal key shall be had to decrypt it.
Note: We have already generated two GPG keypairs for the demonstration objective, one for “john” and the opposite for “fred” on two separate methods. Now, we will be able to export john’s personal and public key, then import it at the different gadget.
How to export public key with GPG
Before sending your public key to a correspondent, you will have to first export it the usage of the gpg command. In the gpg command, an extra argument is specified for figuring out the general public key, which would be the consumer ID “uid” in our case, and to generate the output of the exported document in ASCII structure, the “-a” or “–armor” choice is added within the “gpg” command.
To export a specific public key, to start with, listing out the generated GPG keys for your gadget and choose the important thing which you wish to have to export. To achieve this, execute the below-given “GPG” command:
For example, for exporting the general public key of the consumer “john,” we will be able to be aware down its consumer ID “uid” from the listing:
To export the general public key of “john,” we will be able to upload the “–export” choice within the GPG command. Here, the “-a” choice is applied for developing an ASCII illustration of the general public key, and the “>” redirect operator is used for redirecting the output of the gpg command to the “public.key” document:
$ gpg –export -a john > public.key
The error-free output publicizes that our “public.key” document is all in a position to export. To take a look at its content material, execute the next “cat” command:
As you’ll be able to see, the “public.key” has saved the ASCII illustration of john’s public key:
How to export personal key with gpg
Exporting a GPG personal key comes in handy if in case you have more than one computer systems and need one key pair for all methods. In this example, the “gpg” command lets you export the personal key from the gadget the place you’ve got generated the important thing pair to all different computer systems. Also, in the event you belong to a particular staff and need to create a unmarried key-pair gadget for all staff contributors, you’ll be able to export the personal key and percentage it with the gang contributors. After that, your staff contributors can import that particular personal key to their methods. This operation will determine a simplified gadget, the place the one public key shall be required for sending the encrypted information or paperwork to more than one recipients.
The “–export-secret-key” choice is added within the “gpg” command for exporting the personal key. To export the personal key of “john” in ASCII structure, we will be able to sort out the next “gpg” command:
$ gpg –export-secret-key -a john > personal key
Enter a robust passphrase for exporting the personal key. The receiver will use this passphrase for uploading the exported personal key. For example, in our case, the opposite gadget consumer will make the most of this passphrase for uploading the “private.key” in its Secret keyring:
After clicking the “OK” button, the “private.key” document shall be generated with the related passphrase:
You can take a look at the content material of the “private.key” document to understand in case your personal secret’s effectively transformed to ASCII illustration:
Till this level, now we have created two information, “public.key” and “private.key” that comprise the ASCII illustration of the private and non-private key of “john” uid, respectively. Now, we will be able to percentage those information with every other gadget consumer in order that the “newuser” can import the GPG keys to its keyrings.
How to import public key with GPG
With the gpg command, uploading a public key for your keyring is so simple as exporting them. By uploading the sender’s public key, you’ll be able to decrypt the won encrypted information, paperwork, or emails.
In the former segment, we confirmed the process to export john’s “public.key”. Now, we will be able to information you in regards to the process of uploading it on every other “newuser” account. Before uploading the “public.key”, we will be able to listing out the keys provide within the keyring:
Currently, “newuser” has best the GPG keypair for “fred” uid, which can also be noticed within the following output:
Now, to import the toilet’s “public.key”, we will be able to execute the “gpg” command with the “–import” choice:
$ gpg –import public.key
The below-given output presentations that the general public key of “john” is imported effectively:
For the affirmation of the desired operation, we will be able to listing out the “newuser” Public keyring:
John’s public secret’s imported effectively, which can also be noticed within the below-given symbol:
How to import personal key with GPG
The following GPG command will assist us to import the “private.key” of the “john” to the Secret keyring of the “newuser”:
$ gpg –import personal.key
You shall be requested to go into the passphrase used whilst exporting the toilet’s personal.key. After typing out that passphrase, click on at the “OK” button:
The output will assist you to know that the name of the game secret’s imported:
For the verification objective, you’ll be able to additionally listing out the personal keys which can be provide within the Secret keyring:
Now, take a look at john’s secret key within the below-given output:
Conclusion
To be in contact with each and every different the usage of the GPG key cryptography methodology, the meant recipients will have to have a replica of your GPG keys. In this kind of case, you’ll be able to export your GPG keypair with the correspondents, after which they may be able to import it to their keyring the usage of the GPG command. After that, you’ll be able to ship the encrypted information, paperwork, or emails, and the specific receiver will decrypt them simply. This write-up confirmed you easy methods to export and import the usage of GPG. Moreover, a realistic instance could also be supplied to show the process of exporting and uploading GPG keys between two methods.