How to Encrypt Files in Linux

You may not want people to see important files on your computer, particularly if it has multiple users. There are several different ways to restrict access to a particular file in the system, but unfortunately, most of them consume a lot...
Method 1 of 2:

Encrypting a File

  1. How to Encrypt Files in Linux Picture 1How to Encrypt Files in Linux Picture 1
    Install GnuPG first. Open the terminal and enter the command sudo apt install gnupg. The installation process will start.
  2. How to Encrypt Files in Linux Picture 2How to Encrypt Files in Linux Picture 2
    Navigate to the folder where you store the file that you are going to encrypt. Right-click and choose Open Terminal from the menu.
  3. How to Encrypt Files in Linux Picture 3How to Encrypt Files in Linux Picture 3
    Enter the the command gpg -c file1.txt, and press Enter. Replace "file1.txt" with the name of the file you want to encrypt.
  4. How to Encrypt Files in Linux Picture 4How to Encrypt Files in Linux Picture 4
    Enter the passphrase. You can choose any suitable passphrase you want; it will as you to re-enter the phrase for the confirmation. Don't forget the phrase!
  5. How to Encrypt Files in Linux Picture 5How to Encrypt Files in Linux Picture 5
    Remove the original file by typing the command rm file1.txt. Replace "file1.txt" with the right file name. Your encrypted file will be created with the extension ".gpg" in the same directory.
  6. How to Encrypt Files in Linux Picture 6How to Encrypt Files in Linux Picture 6
    Reload the agent. Sometimes GnuPG will cache your passphrase, meaning anyone can decrypt the file without the passphrase. To avoid this, use the command gpg-connect-agent reloadagent /bye.
Method 2 of 2:

Decrypting the File

  1. How to Encrypt Files in Linux Picture 7How to Encrypt Files in Linux Picture 7
    Open the terminal to the folder where your encrypted file is located. The file has the .gpg extension. Just copy the name of the file from there.
  2. Type the command gpg file1.txt.gpg. Remember to type your file name instead of "file1.txt.gpg".
  3. How to Encrypt Files in Linux Picture 8How to Encrypt Files in Linux Picture 8
    Enter the passphrase.
  4. Wait for your original file to be generated. Then you can open it!
4.5 ★ | 2 Vote