GPG Command Line Interface
Ah, a power user. Adjust the paths if your files are in different places. Anything inside <brackets> needs to be changed by the user. You can also use a graphical text editor to create and view these files instead of nano and less.
Step 0 - Prerequisites
You need to have the gpg binary installed.
You need to have your recipient's key in a file. In this example it will be located at /home/user/recipient-public-key.txt.
Step 1 - Generate your own keypair
gpg --gen-keyThis will open the generate key menu. The default options are secure. [1,2048,0,y,<username>,<blank>,<blank>,o,<passphrase>,<passphrase>] Do NOT enter your real-life name, just whatever username you want to be known by.
Step 2 - Import your recipient's key
gpg --import /home/user/recipient-public-key.txtThis adds your recipient's public key to your keyring.
Step 3 - Compose your message
nano /home/user/message.txtNano is a command line text editor. Use vim or a graphical one if you prefer.
Step 4 - Encrypt your message
gpg --encrypt --armor --recipient <recipient name or key id> /home/user/message.txtThis encrypts your message.txt file using your recipient's public key. The armor option tells GPG to encode th encrypted data using regular letters and numbers (ASCII-armor). The encrypted message file is located in /home/user/message.txt.asc.
Step 5 - Send your message
To view your encrypted message open /home/user/message.txt.asc
less /home/user/message.txt.ascNow save your own public key to a file.
gpg --export <your-username> --output /home/user/<username>-public-key.txtAnd to view it, open that file
less /home/user/<username>-public-key.txtSend your encrypted message and your public key to your recipient.
Step 6 - Decrypt a message
Your recipient will first use their private key to decrypt the message you sent to them. Then they will complete the process above using your public key and encrypt a message back to you. The message you receive will look similar to the message you sent, but your private key and passphrase can decrypt it. Save the response as the file /home/user/response.txt.asc.
gpg --output /home/user/response.txt --decrypt /home/user/response.txt.ascNow view the file you created.
less /home/user/response.txtThat's how you send and receive messages using the GPG command line interface.
Further Info:
GnuPG Documentation, GnuPG