Encrypt a file in Linux

Encrypt a file in Linux

 
# vim test.txt (write something here)
 
This is a Test file
 
:wq
Now see the Content of the file using cat command
 
# cat test.txt
 
This is Test file
 
Now we are going to Encrypt the file with gpg
 
# gpg -c test.txt
 
Enter Pass-phrase : <YOUR-PASSWORD>
Repeat Pass-phrase : <YOUR-PASSWORD>
 
You can see one more file create
 
# ls -l test*
-rw-rr 1 root root 59 2011-03-02 17:20 test.txt
-rw-rr 1 root root 97 2011-03-02 17:23 test.txt.gpg
 
Lets try to see encrypt file with cat command
 
# cat test.txt.gpg
i+`P$@CoEkW%>o
8*zbB`EA9{7
IW
 
Delete original File
 
# rm test.txt
 
Now we are going to decrypt the encrypted file
 
# gpg test.txt.gpg
Enter Pass-phrase : <YOUR-PASSWORD>
 
See decrypted file content
 
# cat test.txt
This is a Test file