HomeLinuxLinux File Encryption

Linux File Encryption


Linux file encryption includes rewriting the plaintext paperwork right into a format that may solely be accessed by these with the best password or decryption key. That is completed to forestall the unauthorized entry to delicate info. Linux helps various encryption strategies together with symmetric encryption which employs the exact same key for encryption and decryption, filesystem-level encryption, and public-private key uneven encryption. Linux customers ceaselessly use GnuPG, OpenSSL, and dm-crypt as encryption instruments. On this information, we’ll use the GPG utility to encrypt the Linux recordsdata and decrypt them.

Replace the System

The very first thing to do is to replace your system earlier than the set up of any utility. The next command updates the bundle listing on an Ubuntu system. Utilizing the “sudo” command, the “omar” consumer runs the command with superuser rights.  The system is related to a bundle repository at “http://pk.archive.ubuntu.com/ubuntu” and is in search of updates.

omar@virtualbox:~$ sudo apt-get replace

 

Set up the GPG

The GPG is the device that’s utilized in Linux to encrypt the recordsdata. The next command is used to put in the “gpg” (GNU Privateness Guard) software program bundle on the system. Run the command with administrative rights by typing “sudo.” A utility to handle the packages on Debian-based computer systems known as “apt-get.” The “set up” command instructs the apt-get to arrange the chosen “gpg” bundle. The output exhibits that the “gpg” bundle is already put in on the system and is the most recent model (2.2.27-3ubuntu2.1). The bundle can be set to be manually put in which implies that it’s put in by a consumer quite than being a dependency of one other bundle. The output additionally states that two packages, “libflashrom1” and “libftdi1-2”, are now not required and may be eliminated utilizing the “apt autoremove” command. Lastly, the output states that there are 0 upgraded packages, 0 newly put in packages, 0 packages to be eliminated, and 37 un-upgraded packages. No adjustments are made to the system’s packages and all packages are up-to-date.

omar@virtualbox:~$ sudo apt-get set up gpg

 

File Encryption

To encrypt in Linux, we must always have a file with some necessary content material in it. Thus, we use the “contact” instruction to create a brand new file within the present working listing which is go.txt.

omar@virtualbox:~$ contact go.txt

 
The “ls” question of Linux exhibits that the newly created “go.txt” file is listed within the present working listing.

omar@virtualbox:~$ ls
Desktop    Downloads  new       Photos  snap       Movies
Paperwork  Music      go.txt  Public    Templates

 
Make certain so as to add some content material to your newly made file. We additionally add some info relating to our system consumer within the “go.txt” file by manually opening it. The “Cat” instruction can be utilized to show the contents of any kind of file as proven within the hooked up command and output:

omar@virtualbox:~$ cat go.txt
Password: Omar

 
The “gpg -c go.txt” command makes use of the GNU Privateness Guard (GPG) device to encrypt a file known as “go.txt” utilizing the symmetric-key encryption. The “-c” choice tells GPG to make use of the symmetric-key encryption and prompts the consumer to enter any passphrase to make use of because the encryption key. The encrypted file is created utilizing the identical title as the unique file and the “.gpg” file extension.

omar@virtualbox:~$ gpg -c go.txt

 
The dialog field seems in your display screen which prompts you to enter the passphrase as proven within the picture. We add the passphrase and tapp the “OK” button:


The very subsequent display screen exhibits a warning when you enter an insecure passphrase. Select the “Take this one anyway” choice to proceed.


The listing instruction shows the encrypted “go.txt.gpg” file which is listed with the opposite recordsdata within the present listing.

omar@virtualbox:~$ ls
Desktop       Downloads   new        go.txt.gpg    Public    Templates
Paperwork  Music          go.txt    Photos          snap       Movies

 
The “file” instruction is utilized to ascertain the kind of a “go.txt.gpg” file based mostly on its contents, quite than its file identify or file extension. The output signifies that the “go.txt.gpg” file is a GPG symmetrically encrypted file, and it’s encrypted utilizing the AES256 cipher. The AES256 cipher is a symmetric key encryption algorithm. AES (Superior Encryption Normal) is a broadly used encryption normal, and 256 refers back to the key dimension which implies that it has a key dimension of 256-bit.

omar@virtualbox:~$ file go.txt.gpg
go.txt.gpg: GPG symmetrically encrypted knowledge (AES256 cipher)

 
Now, while you attempt to show the contents of an encrypted “go.txt.gpg” file, we must always get the next output utilizing the “Cat” instruction together with the file identify:

omar@virtualbox:~$ cat go.txt.gpg
�       ��7$�Z$��Ok��^��On���
����ok.�Ok�{��dE�֛_���$�
                     ��6ay�jȚ�N:�*w�:�껎~��4j

 
After the encryption of a “go.txt” file to a brand new file, there is no such thing as a want to stay utilizing the unique file which is the go.txt. Subsequently, we take away it utilizing the “rm” instruction.

omar@virtualbox:~$ rm go.txt

 

File Decryption

It’s time to decrypt the unique knowledge from the encrypted “go.txt.gpg” file. For this, we don’t want the unique “go.txt” file right here since we already deleted it as per the “ls” command.

omar@virtualbox:~$ ls
Desktop       Downloads  new              Photos    snap          Movies
Paperwork  Music          go.txt.gpg  Public      Templates

 
To decrypt the encrypted “go.txt.gpg” file, we forged off the next “gpg” instruction on the shell. It makes use of the “>” operator to go the decrypted content material to a “go.txt” file that makes use of the GNU Privateness Guard (GPG) device to decrypt a “go.txt.gpg” file utilizing symmetric-key decryption. The “–decrypt” choice tells GPG to carry out the decryption, and the “> go.txt” redirects the output of the decryption course of to a file known as “go.txt”.

The primary output line signifies that the info within the go.txt.gpg file is encrypted utilizing the AES256 cipher in CFB(Cipher Suggestions) mode. The second output line, “gpg: encrypted with 1 passphrase”, signifies that the go.txt.gpg file is encrypted with a single passphrase. A passphrase is a sequence of phrases or different textual content that’s used to encrypt a file, and it’s required to decrypt the file.

omar@virtualbox:~$ gpg –decrypt go.txt.gpg > go.txt
gpg: AES256.CFB encrypted knowledge
gpg: encrypted with 1 passphrase

 
Now, we’ve got a go.txt file again within the present working listing as per the next “ls” instruction output:

omar@virtualbox:~$ ls
Desktop       Downloads  new              go.txt     Photos       snap          Movies
Paperwork  Music          go.txt.gpg  Public      Templates

 
If you attempt to show the content material of a go.txt file on the Linux shell utilizing the cat instruction, it shows the unique content material earlier than the encryption of a file.

omar@virtualbox:~$ cat go.txt
Password: Omar

 

Conclusion

The introduction demonstrates the usage of encryption in Linux methods and discusses its sorts as nicely. To help the subject, we put in the GPG utility that’s particularly designed for the encryption of Linux-based recordsdata. After its set up, we generated a easy textual content file and encrypted it utilizing the “gpg” utility and added the passphrase for encryption for example. Lastly, we tried the GPG utility to decrypt a file to its authentic kind and show the unique content material on the shell.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments