Ubuntu

How to Encrypt File System in Ubuntu?

How to Encrypt File Systems in Ubuntu

Ubuntu is among the secured distros of Linux Distributions. It provides us with cryptographic packages which enable them to run in high-security environments. While maintaining a secure system is crucial, ensuring the security of your files and folders within the Linux file system is equally important.

This article discusses the process and steps required to make our Ubuntu system more secure.

How to Encrypt File System in Ubuntu 22.04?

A File Encryption System is the process of Encoding Files which makes the file undecipherable. The encrypted file can only be accessed or read by an authenticated user. The step-by-step procedure for encrypting files and folders with passwords in Ubuntu is explained below.

How to Encrypt a File in Ubuntu?

With encryption, the privacy and security of our files and folders can be enhanced. The data that is sensitive should be kept encrypted. Follow the steps below to encrypt files in Ubuntu.

Step 1: Install GnuPG

GnuPG or “Pretty Good Privacy” is a free replacement for Symantec’s cryptography suites. It has a versatile key management system and helps to encrypt your data. To install GnuPG use the command:

sudo apt install gnupg2

Step 2: Setting Cipher Algorithm

A Cipher Algorithm is used to Encrypt and Decrypt Data or a File. With the Cipher Algorithm, we can convert a plaintext into a ciphertext. The ciphertext is unreadable and it has to be converted into plaintext using a Key, to be read by a normal user. Some popular Cipher algorithms are AES and DES. To set the cipher algorithm, first, get the list of various ciphers using the command:

gpg2 --version

Change the Algorithm and set AES Cipher Algorithm AES256 as default in the configuration file. Run the command below to change and edit the configuration file:

gedit ~/.gnupg/gpg.conf

Once you run the command it will open up the configuration file:

To change the default Cipher Algorithm, add the line below to the empty file:

cipher-Algo AES256

Save the file and then close it:

Step 3: Encrypting File

To encrypt a file, we will use the asymmetric key encryption method. But before that make a new text file, or use any text file you want to encrypt using the command:

cat > encrypted.txt

Add the content to the text file, save it, and then exit:

For Encryption, use the command below:

gpg --symmetric ~/encrypted.txt

Once the command is executed, it will ask for a passcode:

Enter the passphrase. You can also add your passphrase in the Password Manager. After adding the passphrase, you will notice another text file is created:

Once you open the file you will see that the file is encrypted:

How to Decrypt Files in Ubuntu?

Files can also be decrypted in Ubuntu. Decrypt an encrypted file using the command:

gpg -d encrypted.txt.gpg

Pressing “Enter” will ask for the paraphrase of the encrypted file.

Once you enter the passphrase, the decrypted message inside the file will be shown in the terminal:

How to Encrypt a Folder in Ubuntu 22.04?

To encrypt a folder in Ubuntu follow the steps depicted below.

Step 1: Install GPG

For encrypting a folder, install the GPG Package. The GPG Package in Ubuntu is a tool used to provide digital Encryption and Decryption and can be used to manage Keys. Install GPG using the command:

sudo apt install gpg

Step 2: Compress the Folder

To encrypt the folder, we have to compress it first using the command:

tar -cvzf EncryptedFolder1.tar.gz EncryptedFolder1

This command will compress the “EncryptedFolder1” into “EncryptedFolder1.tar.gz”:

Executing the command will create the new folder:

Step 3: Encrypt the Folder

To encrypt this folder now, use the command:

gpg -c EncryptedFolder1.tar.gz

“-c” command will enable symmetric encryption:

Pressing “Enter” and executing the command will open a dialog box asking for a Passphrase. Enter the Passphrase and press “OK”:

After entering the passphrase you can see the folder is created in the directory:

When you open the folder you can see the content inside the folder is Encrypted:

How to Decrypt a Folder in Ubuntu 22.04?

The “gpg” command can also be used to decrypt a folder that is already encrypted. In our case, will use the “gpg” command to decrypt the following folder:

The “gpg” command will make a new .tar folder when it decrypts the encrypted folder and can be used as follows:

gpg --decrypt 'encrypted-folder.tar.gz.gpg' > 'decrypted-folder.tar'

In our case:

gpg --decrypt EncryptedFolder.tar.gz.gpg > DecryptedFolder.tar

This will Decrypt the Encrypted Folder by making a new .tar Folder “DecryptedFolder”:

You can now extract this “.tar” folder which will make a new Directory with the same name. Extract the file by right-clicking on the file:

The “.tar” folder will make a new Folder in the same path when extracted:

You can now access the files inside the Decrypted Folder.

Conclusion

To encrypt a file in Ubuntu 22.04, first, install GnuPG, set the cipher algorithm, and then encrypt the file using the “gpg –symmetric ~/filename” command. Encryption is a part of security methods. Encryption can further enhance the privacy and security of our files and folders. Most of the data that is sensitive should be kept encrypted. This article guides you on how you can use the encryption method to encrypt your files and folders.

Similar Posts