Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

Protect your files with GnuPG

Hello, friends. In this post, you will learn a useful and simple trick that will help you to protect files. To achieve this, use GnuPG.

What is GnuPG?

According to the project’s website

GnuPG is a complete and free implementation of the OpenPGP standard as defined by RFC4880 (also known as PGP). GnuPG allows you to encrypt and sign your data and communications; it features a versatile key management system, along with access modules for all kinds of public key directories.

In other words, thanks to GnuPG we will be able to obtain several functionalities around file encryption but also signatures for repositories.

Being an open-source project, it is possible to find it without too many problems in many Linux distributions. So, it is easy to install and use it.

Let’s use it to protect a specific file.

Protecting files using GnuPG in Ubuntu / Debian

The procedure is basic because we only need a password or a private key, or even both. As this post is oriented to novice users, I will only show you how to do it with a password.

First, open a terminal or start SSH session on the server and update the machine

sudo apt update
sudo apt upgrade

Thereafter, you can install GnuPG in case it is not already installed.

sudo apt install gnupg

Then check the installed version

gpg --version

Sample Output:

gpg (GnuPG) 2.2.27
libgcrypt 1.9.4
Copyright (C) 2021 Free Software Foundation, Inc.
License GNU GPL-3.0-or-later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: /home/angelo/.gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

Now you can use it. For this little lab, I used this directory structure, but it works for any directory structure.

When you decide which file you want to encrypt to protect it, you can run

gpg -c [file]

For example,

sudo gpg -c vip/sample1.txt

As soon as you start the process, you will be prompted to create a strong password of at least 8 characters, but less at your own risk.

The process will take some time, depending on the size of the file and the quality of your computer.

This will generate a .gpg file that you will have to decrypt if you want to use it. In this case, I have moved it to another directory for testing. If you would like to use the txt file again, then you just need to run.

sudo gpg [file.gpg]

Then you will see this image

Protect files using GnuPG
Protect files using GnuPG

As you can see, you can open again the txt file

cat sample1.txt

No problem. This is ideal for sharing files between colleagues or even in professional situations.

That’s all

Conclusion

In this simple post, you learned how to protect files to be decrypted later. Although it is not the best solution, it can be useful in many situations.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook

x