How to encrypt and decrypt files using gpg in Linux

Use the following command to generate a key (if you already have a key, you can skip this step):

#gpg –gen-key

Note: it asked me to input some info, I choose default for everything except for name, email, and passphrase. My inputs are gpg_encrypt(name), myemail@gmail.com(email), and simonljb(passphrase).

The key generation process is very long, so be patient.  Once the key is generated, you are ready to encrypt some files.

I have a file named test, and the contents of the file are:

This is a testing file.  The contents will be encrypted.

Use the following command to encrypt the file:

# gpg -e -r gpg_encrypt test

Note: gpg_encrypt is the name you entered during the key generation process.
A new file test.gpg will be generated, and the contents of the file are:

<85>^A^L^C^PK¡\ëõÎÆ^A^H^@<89>ønNB]+>zá^Y´ìÌ<92>;æ½ÒA<9f>ÉñÆi¼<9Ãœ<98>^YÃŽt<94>þ^\sK^R<84><8d>< ù×^A<9c>!©h¦ ÂÂúó^[aèã^VhSøÄj^W<8Z\Ø^^Fß<9e>^ZÚN¦¸·mÀ^Nh}¿.nàþ.V½{^KÛ®ªÃg<81>^M<91>xé¹ÇCª³<8f><92>ùµé#ïÄ]<89>Ã’ZÃ^V;r^CÂÚÖ^@ÃŒ<88>ø”aR©à/<82><8b>pÛò±^Kt^Düo^X^JÓ¥^XJÖ^^Ø^\^DÃ…cc^G­£<83><85>ª­í¼^_¢^^¡Q.ÖøJCËZ\XE^^^OÃ¥D<8d>ËvvÀ¤ßF0^_^CÉéCXX Ã…^P”Ã
^;<86>kO~SX4/<83>^W¡Öt ^C·)xÇu·apÿYâú^?^RT-Nm^T*ù¯^@Ê¥µX-7;MTzø¾pw<96>RÅ~<9f>Å<94>y_A

To decrypt the file, use the command:

# gpg –output test2 –decrypt test.gpg

Type in your passphrase to decrypt test.gpg, and a decryped file test2 will be generated. The contents of test2 should be the same as the original test file:

This is a testing file.  The contents will be encrypted.

 

Reference: http://forum.codecall.net/topic/48235-gpggnupg-encyrption-tutorial/

Advertisements
This entry was posted in Linux Tips. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s