Steps for Person 1

The first step is to import the person’s (Person 2) public key information, to whom you would like to send the secret file, into your system. You can do this in two ways:

Method 1:

Import Person 2’s public key using a file that he/she might have send you in an email. Suppose the file is called person2_pub_key.txt. Give the following command to import it:

person1:~# gpg --import person2_pub_key.txt

Note: The public key is generated as explained in Step 5 of Part 1. We are assuming that Person 2 has followed Part 1 and generated the file pubkey.txt and send it to you after renaming it to person2_pub_key.txt

Method 2:

Another method is to search for Person 2’s public key information on the GPG keyserver. We can only use this method if the Person 2 did Step 6 of Part 1. You can search for Person 2’s key using the following command:

The 2nd key information (in Italics) is Person 2’s information to whom you would like to send the encrypted file.

Step 3: Encrypt the file using your private key

Now we are fully ready to encrypt the file using public key of Person 2 from above steps.

person1:~# gpg --encrypt --recipient 'person2@abc.com'' account.txt

Note: You might get some warning messages regarding the authenticity of the public key. Simple ignore and say yes (“y”), since we fully trust Person 2.

Now a file called account.txt.gpg should be created. This is our encrypted file and you if you try to open it using a text editor you see garbage in it which basically means that your encryption process was successful.

Step 4: Send the encrypted file to Person 2

Now we simply need to send this encrypted file to Person 2 through e-mail or any other storage media. Once you (Person 1) send it the file to your friend (Person 2) your job is done and now the Person 2 has to do some work to decrypt it so that he/she can read the message.

Steps for Person 2

Now Person 2 has to do the exact same Step 1 and Step 2 from above with the only difference of substituting Person 2’s information with Person 1’s. Basically he/she will fist have to import Person 1’s public key and then verify if it got imported successfully or not. I have summarized this as follow:

Finally the Person 2 can decrypt the file account.txt.gpg with the following command:

person2:~# gpg --output account.txt --decrypt account.txt.gpg

You will be asked for your paraphrase (from Step 2 in Part 1) in order to decrypt the file. After entering your paraphrase you should see a file called account.txt (as specified in the –output option in above command) and you now view it content’s using any text editor.

Other Related Posts:

Kushal Koolwal works as an Operating Systems (OS) R&D Engineer at VersaLogic Corporation, an embedded systems manufacturer located in Eugene, Oregon. In his current position Mr. Koolwal works with different embedded operating systems such as Windows Embedded, Linux, VxWorks, QNX, etc. Kushal completed his bachelor’s degree in Computer Engineering in 2004 in India. He then pursued a Master’s degree in Computer Science, which he received in 2006 followed by an MBA in 2008, both from the University of Oregon. Additionally, Kushal is a database/web developer using .NET technologies and blogs about Linux solutions and businesses in general. His hobbies are traveling, playing sports, dancing, etc.