How to use GPG?

How to create key?

Simply we can run this:

gpg --full-gen-key

Then we will have some interactives.

  1. Key Type

    It's optional, but I oftenly use RSA and RSA (number 1)

  2. Keysize (Bits)

    It's more secure to have more bit or simply we can take the maximum bit, let's say maximum number is 4096, then we can put 4096

  3. Expiration Time

    If we want to use this key on all the time, we can set to 0 to have the never expired key.

  4. Expiration confirmation

    let say I set 0 as the expiration date which mean it will never get expired, then it will try to confirm us that we really want to create a key which never get expired.

  5. Identity

    1. Name

      Put your name, minimum length is 5.

    2. Email

      You'll never get email for this, it's just for identification purposes. (optional)

    3. Comment

      Just another information we want to put, maybe to identifying something. (optional)

  6. Identity confirmation

    It will ask you to confirm your identity, we can input O (O / Oscar character) to confirm that it's correct.

  7. Password

    Finally we can put password for the created key, we're going to need this password to decrypt encrypted file.

How to Encrypt file?

gpg -r <uid> -e your-whatever-file.zip

replace <uid> with your created key, then a new file with the .gpg extension will be created.

How to Decrypt File?

gpg -d your-whatever-file.zip.gpg

or if we want to put the unlocked data into a file, we can use

gpg -d your-whatever-file.zip.gpg > your-whatever-file.zip

How to List all existing keys?

gpg --list-keys

or we can just specify a <uid> to know the information of specific key

gpg --list-keys <uid>

How to Export Key?

gpg --export-secret-keys <uid> > output.key

You're going to type your password to able to export the key.

How to Import Key?

gpg --import output.key

How to Delete Key?

to be able to delete the keys, we need to delete the secret key first, then deleting the key.

gpg --delete-secret-keys <uid>
gpg --delete-keys <ui>

References:

Did you find this article valuable?

Support Fiko Borizqy by becoming a sponsor. Any amount is appreciated!