Encrypt Ubuntu Linux files from the terminal using GnuPG

Gnu Privacy Guard (GPG) is a encryption program that many of you will know because it is widely used in GNU / Linux systems, for example it is used to increase repository security, it supports various encryption algorithms

  • 3DES
  • CAST5
  • AES, AES192, AES256,

many of you will not be interested in how each algorithm works, but you will surely be interested in how safe one is compared to the other: let's say right away that any of these algorithms is good for protecting our personal files, hardly our PC home will be subject to massive attacks to decrypt our files, having said that, the Safer algorithms are BEA, TWOFISH e CAMELLIA while by default GnuPG uses CAST5 (key to 128bit) which, as mentioned above, is more than fine to secure our files.

GPG it is already pre-installed in Ubuntu, let's see how to use it simply from a terminal: in fact, with a simple command we can encrypt every type of file on our hard disk:

If we wanted to encrypt a text file called "prova.txt"Which is in our folder"Documents"It will be sufficient to open the terminal and go to the document folder using the command:

cd ~ / Documents

the command "cd"Allows us to move between the various folders of our PC the generic syntax is"cd”Followed by folder path to open, for example if we wanted to open the folder “video"Located inside the folder"Downloads"We will write in the terminal:

cd ~ / Downloaded / video

alternatively we can go to the folder Documents means fillet manager and with the right key mouse open a terminal in the desired position

open terminal

after having positioned ourselves correctly in the file folder "prova.txt", We can encrypt it with the following syntax:

gpg -c prova.txt

naturally we will have to modify the name "prova.txt" with the exact name of the file to be encrypted; we will be required for 2 times to enter a password that will allow us to decrypt the file later (be careful not to forget your password because there will be no way to recover the file without it).

this command will create a new encrypted file with the same name, in this case "prova.txt.gpg"That if we try to open it it will be indecipherable with any program; at this point we delete the "prova.txt" file in clear, leaving only the one encrypted in our hard disk.

to decrypt the file use the following command:

gpg prova.txt.gpg

the decryption password will be requested, once entered it will recreate the original file in clear “prova.txt”

do not perform this procedure for the first time on important files, but try the procedure on a test file.

we carry out the same procedure for encrypt an image (Inthebit.png):

gpg -c inthebit.png #create encrypted inthebit.png.gpg

Encrypt Ubuntu files

Encrypt Ubuntu files

we can now delete the image in clear inthebit.png leaving the one with the .gpg extension that will result unreadable from any image viewing program.

gpg inthebit.png.gpg #decrypt the .png image

to encrypt a folder instead it will be enough to compress it with any compression program: .zip, .7zip, .rar and carry out the same procedure seen until now.

if we wanted to change the encryption algorithm the command is the following: 

gpg -ca –cipher-algo twofish test.txt # file encryption test.txt using twofish algorithm

gpg test.txt.asc #decrypting with twofish algorithm - note that the file encrypted with this algorithm has the extension .asc

secure your personal files is simple! never leave documents that contain your passwords, other registration or financial data without any protection, one day you may regret it.

💣 Don't get away Xiaomi Mi Electric Scooter Pro 2 Global on offer for only 375 € with Mi Band 5 as a gift and free shipping from Europe!

Receive the latest posts by email

Enter the email and choose the inscriptions on the new page

Added devices
  • Compare Smartphone (0)