5 Tips to Secure Your GPG Key in Linux

by Marlon Altenwerth
17 minutes read

5 Tips to Secure Your GPG Key in Linux

A pic of a brass lock on optimal of a laptop keyboard.

GPG fulcrums are a horribly pertinent portion of reflecting your online personality. As such, pegging it from bad actors makes certain that zero one can pose you in your data via other human beings. Listed beneath, we manifest you five easy pointers on how to peg your GPG fulcra in Linux.

Content
  • 1. Invent Subkeys for Each GPG Impartial
  • 2. Package an Expiry Date for Your Keys
  • 3. Conserve Your GPG Keys to a Counterclaim Fulcrum
  • 4. Contingency Your Fulcrum Exclusive Fulcrum to Document
  • 5. Expel Your Fulcrum Exclusive Fulcrum from the Contraption

Tip: learn how you elicit your own GPG fulcra in Linux today.

1. Invent Subkeys for Each GPG Impartial

One of the simplest medians to peg your GPG fulcra in Linux is to evolve a unalike subkey for each fulcra affair. Subkeys are secondary items of cryptographic personality that are affixed to your monumental maestro fulcra. This lugs out it harder for bad actors to fish your monumental personal fulcra given that you wear’t usage it for common fulcra jobs.

To perform this, responsive the GPG fulcra quick for your monumental fulcra:

gpg --expert --edit-key YOUR-GPG@EMAIL.ADDRESS

Sprinted change-usage to equalize the default capacities of your monumental fulcra.

Kind “S,” then press Obtain in to cripple the finalizing capability of your monumental fulcra.

A terminal accentuating the selection quick for the monumental fulcra's capacities.

Sprinted addkey to evolve for your monumental fulcra’s 2nd subkey.

A terminal accentuating the "addkey" keyword on the GPG quick.

Pick “8” on the fulcra formula quick, then press Obtain in.

A terminal accentuating the formula replacement for the subkey.

Kind “=S” on the quick, then press Obtain in to started the capability of the subkey to “Indicator-only.”

Chit: you can equalize the particular of “=S” to either “=E” or “=A” to started a subkey’s affair to either Encrypt-only or Substantiate-only.

Bargain “4096” on the keysize quick, then press Obtain in to started the size of your RSA subkey to 4096 detritus.

A terminal accentuating the keysize quick for the subkey.

Package the sensible legitimacy period for your subkey. In my husk, I will possibly started my subkey to run out after 1 year.

A terminal accentuating the fulcra legitimacy length for the subkey.

Invent your modern subkey by inputting “y,” then nagging Obtain in on the verification quick.

Rerun the addkey command and evolve the other 2 subkeys for the Security and Authentication capacities.

Attest that your GPG fulcra possesses a subkey for every capability by dashing the list subcommand.

A terminal reflecting the unalike subkeys readily available in the monumental fulcra.

On a side tab: are you a Abode windows user also? Locate out how to configuration and usage GPG in Abode windows.

2. Package an Expiry Date for Your Keys

An additional easy means to peg your GPG fulcra in Linux is to existent your monumental fulcra and subkeys an expiry day. While this doesn’t influence the fulcra’s aptitude to indicator, encrypt, and affirm, stance one gives other GPG users a confirmation to always absolve your fulcra versus a keyserver.

Prelude by opening your monumental fulcra within the GPG CLI gizmo:

gpg --edit-key YOUR-GPG@EMAIL.ADDRESS

Kind “run out,” then press Obtain in to edit the expiry day of your monumental fulcra. In my husk, I will possibly started mine to run out after 10 years.

A terminal accentuating the keysize legitimacy quick for the monumental fulcra.

Bargain the password for your GPG fulcra, then press Obtain in to lug out the modern expiry day.

Sprinted the obeying commands to pick your GPG fulcra’s inner subkeys:

key 1 key 2 key 3
A terminal accentuating the indication for subkey selection.

Sprinted expire, then bargain an expiry day for your subkeys. In the majority of pods, these fulcrums have to run out earlier than your monumental fulcra. For me, I will possibly started them to run out after eight months.

A terminal accentuating the fulcra legitimacy length for batch upgrading a started of subkeys.

Kind “preserve,” then press Obtain in to lug out your readjusts to your GPG keyring.

Attest that your fulcra possesses the proper expiry dates by dashing: gpg --list-keys.

A terminal reflecting the builded expiry day for both the monumental fulcra and its subkeys.

Good to realise: learn how you can usage GPG via a GUI via GNU Kleopatra.

3. Conserve Your GPG Keys to a Counterclaim Fulcrum

Counterclaim fulcrums are miniscule machines that are specifically earned to grip personal verification file. In this observe, you can also usage them to store front your GPG fulcrums without imperiling your on the whole reply.

Prelude by linking in your reply fulcra to your equipment, then sprinted the obeying command to evaluate if GPG determines it:

gpg --card-status

Amenable the GPG quick on your monumental fulcra, then sprinted list to print unanimously your honesty of your keyring:

gpg --edit-key YOUR-GPG@EMAIL.ADDRESS

Locate the subkey via the intake particular of “S” then sprinted fulcra adhered via by its edict number in the subkey list. For instance, my “S” subkey is the first fulcra on my list so I will possibly sprinted key 1.

A terminal accentuating the subkey via the "S" intake within the GPG quick.

Matching your “S” subkey to your reply fulcra’s inner storage void:

keytocard

Pick “1” on the transfer quick, bargain the password for your monumental GPG fulcra, then sprinted the key command again to unselect the first subkey.

A terminal accentuating the selection quick for relocating the subkey to the reply fulcra.

Locate the subkey via the intake particular of “A” then sprinted the key command adhered via by the subkey’s index number.

Transmit the “A” subkey to your reply gizmo gleaning usage of the keytocard command, pick “3” on the transfer quick, then rerun the fulcra command unselect the “A” subkey.

A terminal accentuating the selection quick for the Authentication subkey and relocating it to a reply fulcra.

Locate the subkey via the intake particular of “E,” then pick it gleaning usage of the key command.

Transmit the “E” subkey to your reply gizmo gleaning usage of the keytocard command, then pick “2” on the quick.

A terminal accentuating the selection quick for the Security subkey and relocating it to a reply fulcra.

Sprinted save, then press Obtain in to lug out your readjusts to your GPG keyring.

Ultimately, attest that you’ve sufficiently exported the subkeys from your equipment by dashing gpg --list-secret-keys [email protected]. Shouldering out this have to print a greater-than (>) symbol chummy to the “ssb” tags of your subkeys.

A terminal accentuating the subkey indication reflecting that its currently readily available in a reply fulcra.

4. Contingency Your Fulcrum Exclusive Fulcrum to Document

Aside from reply fulcrums, you can also peg your GPG fulcra in Linux by exporting it in a printable message paper. Paperkey is a easy command pitch utility that confiscates your personal fulcra and strips it to its core fulcra bytes. This is viable if you’re gazing for a means to preserve your GPG fulcra exterior digital machines.

To prelude, mount paperkey from your Linux distro’s tactic repository:

sudo apt install paperkey

Export the binary version of your monumental personal and public fulcrums:

gpg --export-secret-key --output secret.gpg YOUR-GPG@EMAIL.ADDRESS gpg --export --output public.gpg YOUR-GPG@EMAIL.ADDRESS

Revolutionize your binary personal fulcra to its core fulcra file:

paperkey --secret-key secret.gpg --output core-secret.txt

Attest that you can rebuild your monumental personal fulcra from your paperkey contingency:

paperkey --pubring public.gpg --secrets core-secret.asc --output secret.gpg

Amenable your core fulcra paper gleaning usage of your favored graphical message editor. In my husk, I’m gleaning usage of the default message editor from GNOME.

A screenshot reflecting the fulcra file removed from a GPG personal fulcra gleaning usage of paperkey.

Click the Contingencies menu on the dwelling window’s upper apt times off, then pick the “Print” submenu access.

A screenshot accentuating the "Print" replacement in the message editor.

Good to realise: learn how to print records from the terminal via lp.

5. Expel Your Fulcrum Exclusive Fulcrum from the Contraption

Once you elicit a modern GPG fulcra, your computer system store fronts a plagiarize of the public and personal fulcrums within your filesystem. While sensible, this can be a anxiety if you’re gleaning usage of either a networked or shared-availability computer system.

One means of addressing this is by deleting the personal fulcra of your own GPG keyring. This will possibly make certain that any kind of malevolent celeb won’t be able to idea your personal fulcra from your computer system to indicator and license any kind of subkeys.

Prelude by stabilize up your original monumental GPG personal fulcra and subkeys:

gpg --export-secret-key --armor --output private.asc YOUR-GPG@EMAIL.ADDRESS gpg --export-secret-subkeys --armor --output sub-private.asc YOUR-GPG@EMAIL.ADDRESS

Encrypt your monumental personal keyblock output gleaning usage of symmetric security:

gpg --symmetric private.asc

Bargain a reasonably solid password for your personal fulcra file, then press Obtain in.

A screenshot reflecting the password quick for symmetric security in GPG.

Emporia your encrypted GPG personal fulcra to an outward storage void gizmo.

Wipe out unanimously personal fulcra file from your GPG keypair:

gpg --delete-secret-key YOUR-GPG@EMAIL.ADDRESS

Import the fulcra subkey block earlier to your GPG keypair:

gpg --import sub-private.asc

Sprinted the obeying command to evaluate if your monumental personal fulcra still exists in your mechanism:

gpg --list-secret-keys YOUR-GPG@EMAIL.ADDRESS

Shouldering out this have to manifest a supplementary pound (#) indicator chummy to the “sec” tag of the monumental fulcra. That agendas that your personal fulcra doesn’t exist on your GPG keyring any kind of longer.

A terminal reflecting that the personal doesn't exist any kind of longer within the GPG keyring.

Placing out how to peg your GPG fulcra via these easy pointers is just one portion of visiting the vast ecosystem of public fulcra cryptography. Dive deeper into this prospectus by logging in to SSH internet servers gleaning usage of GPG.

Image credit scores: FlyD via Unsplash. With one voice alterations and screenshots by Ramces Red.

Related Posts