How To Install and Use GPG Encrytion In Linux In Order To Encrypt and Decrypt Files and Folder?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/install-use-gpg-encrytion-linux-order-encrypt-decrypt-files-folder/
PINTEREST
PINTEREST
INSTAGRAM

Security is important part of the today’s IT operations. There are a lot of tools which provides some part of the secure operations. GNU Privacy Guard or simply GPG is a one of them. It provides encryption, decryption, digital signatures and signing.

Install GPG To Ubuntu, Debian, Mint and Kali

For deb or apt based distributions we can install GPG with the following command for gnupg package.

Install GPG To CentOS, Fedora, RHEL

For rpm or yum based distributions we can install GPG with the following command.

Create Private and Public Keys

Now we will start with creating Private and Public Keys. As we know Public Cryptography provides two keys where private key is a secret key which should be protected accordingly. Public key is as its name suggest open to everyone we want to collaborate. So we need these keys. we can create them with the --gen-key option like below.

This command will ask us some questions like below.

Create Private and Public Keys

Create Private and Public Keys

List Keys

We can list keys creted and saved in the current system with the --fingerprint option. We should provide some search term to this option like the email address or individual name etc. In this example we will search with email address ibaydan

List Keys

List Keys

Register To Keyserver

In Public Key Cryptography key distribution is important. We need to provide our Public Key to the others in a open and trusted way. So Keyservers are designed to hold public keys or individuals and corporate. There are different Keyserver’s but pgp.mit.edu is the most popular one. We will use --keyserver option to specify key server and --send-keys to provide fingerprint of the key we want to register.

LEARN MORE  Python Hash Strings and Lists to MD5, SHA256, SHA512 with Hashlib Module

Register To Keyserver

Register To Keyserver

Export Public Key In ASCII Format

In some cases we may want to print the key in more readable format like ASCII.  This will be useful if we want to distribute our public key with email or similar ways. We will use --armor option with output which gets the file name we want to save and  --export the key search term.

Export Public Key In ASCII Format

Export Public Key In ASCII Format

Encrypt A File

We will use our Private Key in order to encrypt given data like a text file. We will use --encrypt with --receipent which will set private key and the last one the file we want to encrypt. We can also use --output option to specify the file name of the encrypted file.

Keep in mind that encrypted file size will be bigger than original file size.

Decrypt A File

Now if we received a file which is encrypted by our Public Keys we need to decrypt it with our Private Key. We will use --decrypt option. We can also optionally specify the output file with --output option like below.

Decrypt A File

Decrypt A File

List Installed Keys

We can list existing keys  with the --list-keys option. This will provide information like path, public key algorithm, user id, etc.

LEARN MORE  How to use GPG(GnuPG)

List Installed Keys

List Installed Keys

Delete Key

As we see in previous example the Keys are stored in a database format named kbx . If we need to remove keys we should use --delete-key with the related term like email.

Delete Key with Secret Keys

While deleting keys if there is related secret we should provide --delete-secret-keys option too. If not we will get error like below.

Delete Key with Secret Keys

Delete Key with Secret Keys

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/install-use-gpg-encrytion-linux-order-encrypt-decrypt-files-folder/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)