Steps to encrypt/decrypt a file in Linux

0
1673

When you send imported text or doc fies  or folders as a atachement by mail, you need to think about security. You should use encryption techniques for your important files or folders  to transferring data online or offline. ( by Mail, Upload your files some where, File or folder copied to USB etc ).

You can encrypt a single file or folder by using gpg command in Linux distributions. With this command encryption method is very easy, you need a password to decrypt a file or folder.

Now I will explain steps to encrypt or decrypt a file or folder in linux. GPG command can be found in almost all linux operating systems.  I am using CentOS Linux release 7.2.1511 (Core) operating system.

Here I will create a text file named as encryption-text-file under my home directory.

Image-1

Step 1:  Open a terminal in your Linux distribution.

Step 2:  Use following command

gpg –symmetric  –cipher-algo AES256    encryption-text-file

when you will run this command , a new window will open where you  can set your password as shown in below image. For your password confirmation, you have to re-enter your password.

Image-2

Now file will be saved as “encryption-text-file.gpg” . Here .gpg is encryption extension. You have sucessfully encrypted your file.

Step 3: Testing of Encryption

Now I will try to open this file using linux cat command.

[root@www]# cat encryption-text-file.gpg

É—æ-zží-ÈÖe@Ò±ø'¡a³TZY½J¦yècJr7ÂáÇ~¼év‘R&À””ªJ< ÉR*³Ò

You will not able to read this text because it is encrypted. 

Step 4: How to decrypt  a file?

To decrypt a text file you have to use again gpg command as explained below.

gpg -o encryption-text-file -d encryption-text-file.gpg

When I will run this command, a new window will open, where you have put password that was used during encrption process as show below image.

Image-3

Your file is sucessfully decrypted your text file. For testing you can open file using cat command as explained below.

[root@www]# cat encryption-text-file

This is test file for Encryption and Decryption test.

Tip : Please use strong passwords during encryption process. 

LEAVE A REPLY