Short guide to encrypt files from the terminal

A while ago we saw how to use GPG en Ubuntu to encrypt files, emails, etc. In this opportunity, we will see how to use GPG from the terminal, procedure that works for any distro Linux. 

This is a contribution from Arnoldo Fuentes, thus becoming one of the winners of our weekly competition: «Share what you know about Linux«. Congratulations Arnoldo!


To encrypt a file:

gpg -c file.txt

It is also possible to encrypt directories

It will ask for a password (phrase) to encrypt it (if you lose the phrase or password you will no longer be able to recover your information).

The above command will generate a binary gpg file. If you prefer that it be encrypted in text mode and not in binary:

gpg -ca file

This will generate a sac file that you will be able to open with any text editor, but it will only see a lot of characters without apparent meaning.

If you want the encrypted file to have another name:

gpg -o encrypted_file.gpg -c file_to_encrypt

If you want to protect a folder that contains many files and subfolders, the ideal is to compress everything into a .TAR.GZ and then protect that file with GPG.


To decrypt it, it would be enough with:

gpg -d file.gpg

It will ask for the specified password (phrase) when encrypting it.


For more information see:

You can also take a look at the manual:

man gpg
gpg -h

GPG is usually installed by default on almost all popular distros. Otherwise, it is more than certain that it will be available in your repositories.

The content of the article adheres to our principles of editorial ethics. To report an error click here!.

13 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   sieg84 said

    that not the word is encrypt?

    1.    ricardo said

      Exactly, the correct word is encrypt, the word "encrypt" does not exist in the dictionary, "encrypt" is a wrong translation of the word "encrypt".

      The same is true of the word "library" which is incorrectly translated as library, especially in the world of programming and whose correct translation is library.

      1.    let's use linux said

        Hi Ricardo!
        I copy and paste from Wikipedia: «Frequently the encryption and decryption processes are called encryption and decryption, both Anglicisms of the English terms encrypt and decrypt, which the Royal Spanish Academy has not yet included in the Dictionary of the Spanish language . The Urgent Spanish Foundation, advised by the Royal Spanish Academy, indicates that encryption is a valid term and that there is no reason to censor its use. "
        To this must be added that in many countries, for example in Argentina, the use of the word "encrypt" is very rare, although its meaning is well understood. Instead, we use "encrypt", "decrypt", "encryption", "encryption" and so on. Of course, as explained in the previous paragraph, it is rather an Anglicism, but very widespread. In any case, it should be noted that it is a "valid" word in Spanish, although it has not yet been included in the DRAE. In other words, it is not the mere use of the word in English, as we do when talking about the "mouse" (not the mouse, as in Spain), the "motherboard" (instead of the "motherboard"), and so on.
        A hug! Paul.

        1.    Ricardo said

          I quote verbatim: The educated norm, and also common sense, dictates that great caution must be exercised when incorporating new words from other languages ​​into the lexicon, as it is highly recommended that languages ​​maintain their features and characteristics, their identity; otherwise, it could lead to a large-scale, difficult-to-solve linguistic entanglement and even the disappearance of one or more languages.

      2.    Drumsman ~ said

        Although it is true, like Ricardo, I am in favor of maintaining the cultural identity of peoples and / or countries, encompassing customs, language, faith, etc., but certainly the language is alive, evolving and reforming at every moment , in a kind of permanent beta state. How to express yourself is within everyone's freedom, but we must be willing to have a well-trained behavior prone to disambiguation, both having an open mind when reading or listening to something, as well as to provide extra information when we do not understand ourselves well with someone, making our contribution to the 'group' to understand each other well. Always help and be patient with the one who always asks questions that for some can be very basic, we have all been through that.

        Greetings from Chile!

  2.   Gustavo Socorro said

    As the post says, it is advisable to compress that folder in .tar.gz format and then send it to encrypt with the commands given here

  3.   Facundo Poblet said

    Hello, in the post you mentioned that it is useful to protect folders that contain many files and subfolders, could you tell how to do to encrypt a folder?

  4.   kuk said

    What type of encryption does it handle?

  5.   desikoder said

    I have the entire hard drive encrypted with LUKS, so I don't need to encrypt files with a symmetric key (gpg can be used like this). However, I have the enigmail to send encrypted mail with gpg ...

  6.   patrician said

    This process system. ..
    when compressing ... the original file will still generate you
    I mean you have a double file

  7.   Eikichi Onizuka said

    The truth is, I don't think that for a normal person this is useful.

    I consider myself Linux and everything, but I have no need to be sending encrypted messages, with all the trouble of looking for public keys, to make sure they are signed and blah blah blah but I RECOGNIZE that it must be invaluable for those who need it.

    With regard to file encryption ... there it seems to me a total nonsense. Many complications (the worst is that of being designed for a single pc ... and if formatting is a problem), and from what I read the comments above, there are bugs too.

  8.   Juan said

    A very strange thing happens to me. When I try to decrypt the file with a gpg extension, I type the command gpg -d plus the name of the encrypted file and the information inside that file appears directly in the terminal without asking me for the password. Is this normal?

    I am doing it on a linux live cd.


  9.   anonymous said

    is that you need to specify the output of the file, the same thing happened to me, you can use this command
    gpg -o file.jpg -d file.jpg.gpg

    fil. jpg is the file that will be created decrypted

    so you will no longer see the screen full of characters and when you look for the file in the path you will see it without encrypting