Files Encryption

There are many ways to encrypt files under Linux, in this post I'll talk about gpg utility to easily encrypt a file under Linux.

Encrypt a file with password:

# gpg -c  aa.txt
Enter passphrase:
Repeat passphrase:


Note: a new encrypted file will be created with name aa.txt.gpg.
Next step you should remove the original file aa.txt to keep only the encrypted version of the file on the system.

Any other user [even if have sufficient privileges on the file] will not be able to view the contents of the encrypted file, it will appear for him in a meaning less letters like this:
e.g.
# su - scott
# ls -l aa.txt.gpg
 -rw-r--r-- 1 scott   scott        164 Jul 29 17:46  aa.txt.gpg
# cat aa.txt.gpg
<8c>^M^D^C^C^B^HéÔt÷Ì^M<89>`É<93>U?<


To decrypt an encrypted file:
# gpg  aa.txt.gpg

gpg: CAST5 encrypted data
Enter passphrase:
gpg: CAST5 encrypted data
gpg: encrypted with 1 passphrase
gpg: WARNING: message was not integrity protected


Note: It will create a new file aa.txt and will keep the encrypted file, so you can remove it later.


You can watch this video to see a gpg tutorial:
http://www.youtube.com/watch?v=T0duUXxnVpg#t=58



No comments:

Post a Comment