Published: July 18, 2026
Read: 11 min
In: Technology & Development

Written by

Reviewed by

Last updated: May 15, 2024

Expert verified

TL;DR

Encrypt files in Linux using these methods:

  1. GnuPG (GPG) Command-Line Encryption:
    • Install: sudo apt install gnupg
    • Create Key Pair: gpg --full-gen-key
    • Encrypt: gpg --encrypt --recipient 'Your Name' file.txt
    • Decrypt: gpg --decrypt file.txt.gpg > decrypted_file.txt
  2. Seahorse GUI Encryption:
    • Install: sudo apt-get install seahorse-nautilus
    • Create keys in the app
    • Right-click file > “Encrypt” > Select recipient’s public key
  3. eCryptfs Filesystem-Based Encryption:
    • Install: sudo apt-get install ecryptfs-utils ecryptfs-setup-private
    • Initialize: ecryptfs-setup-private
    • Move files to ~/Private for automatic encryption

                Keeping your digital data secure is crucial, especially in today’s world, where information breaches are all too common. Whether it’s personal photos, important documents, or sensitive work data, you must protect your files on Linux. Luckily, Linux offers several robust tools and methods for encrypting files, which can shield your data from unauthorized access.

                In this post, I will show you how to use command-line tools like GnuPG and OpenSSL, graphical interfaces, and specific Linux filesystems like eCryptfs and EncFS to encrypt your files. I’ll guide you through each method step-by-step and also point out common mistakes to avoid. This way, you can ensure your data stays secure and only accessible to you.

                How to Encrypt Files in Linux?

                To encrypt files in Linux, you can utilize command-line tools, graphical interfaces, or filesystem-based methods. For command-line encryption, use GnuPG by installing it with sudo apt install gnupg, creating a key via gpg --full-gen-key, and encrypting files with gpg --encrypt --recipient 'Your Name' file.txt. Graphical users can opt for Seahorse in GNOME or Kleopatra in KDE, which provide simple interfaces to encrypt files by selecting a recipient’s public key.

                Additionally, filesystem-based methods like eCryptfs and EncFS offer integrated solutions—eCryptfs encrypts files within specific directories, while EncFS allows you to create a parallel encrypted directory for flexible data protection. Each method ensures your files are securely encrypted according to your specific needs.

                That was the quick answer. Read below for more detailed instructions and additional methods.

                Linux File Encryption Using Command Line

                Using command-line tools like GnuPG and OpenSSL provide powerful encryption directly from the Terminal. GnuPG is great for securing communications with its robust cryptography, while OpenSSL handles complex tasks like managing SSL/TLS protocols. These methods are perfect for those who need precise control and automation in environments without a graphical interface. Here is how to encrypt files using these methods:

                1. GnuPG (GPG)

                GnuPG, or GPG, stands for GNU Privacy Guard. It is a tool for secure communication and data storage. GnuPG uses a combination of conventional symmetric-key cryptography for speed and public-key cryptography for ease of secure key exchange, typically using the RSA or DSA algorithms. Follow these steps to encrypt a file using GnuPG:

                1. Make sure GnuPG is installed on your Linux system. You can install it using the package manager by running the command:

                sudo apt install gnupg
                installing gnupg on ubuntu
                1. Generate a pair of encryption keys by running: 

                gpg --full-gen-key

                This command will create a new encryption key pair. You will be given options to choose which type of key you want to create.

                1. Enter the key size and set the validity period of the key:
                1. Enter username, email, and comment to identify the key:
                1. Enter a security paraphrase for the key:
                1. Encrypt a file using the command:

                gpg --encrypt --recipient 'Your Name' file.txt

                Where Your Name is the name you used when creating your key pair.

                1. To decrypt Linux file, execute the command: