GPG (GNU Privacy Guard): Part 5
Gonna learn how to write, encrypt, send, and decrypt a message with GPG in this one, bruh.
Previous
Create a Simple Message
Open a terminal window and create a new text file called message.txt
containing the message you want to send. For example:
echo "Hello, this is secure and private message." > message.txt
Encrypt the Message
To encrypt the message, run the following command:
gpg --encrypt --recipient [recipient's email address] message.txt
This will create a new file called message.txt.gpg
that contains the encrypted message. Replace [recipient’s email address]
with the email address of the person you want to send the message to.
Attach or Copy the Message
To send the message, you can send the message.txt.gpg
file as an attachment in an email.
Alternatively, you can copy the contents of the message.txt.gpg
file and paste them into the body of an email message.
cat message.txt.gpg | xclip -selection clipboard
This will copy the contents of the message.txt.gpg
file to the clipboard, which you can then paste into an email message or any other application.
Paste the contents of the message.txt.gpg
file into the body of the message by pressing Ctrl+V
(on Windows) or Command+V
(on Mac).
Add the recipient’s email address and any other desired details to the message, and then send the message.
The recipient will need to have GPG installed on their computer and will need to have your public key in their keyring in order to decrypt the message. They can then use the gpg --decrypt
command to decrypt the message, as described in a previous response.
Note
The “xclip” command is not available on all systems. If it is not available on your system, you can use a similar command such as “pbcopy” (on Mac) or “clip” (on Windows).
Decrypt the Message
To decrypt the message, the recipient will need to have GPG installed on their computer and will need to have your public key in their keyring. They can then run the following command:
gpg --decrypt message.txt.gpg
This will prompt the recipient to enter their passphrase, and will create a new file called message.txt
containing the decrypted message.
Note
These steps assume that the recipient already has your public key in their keyring. If they do not, they will need to import your public key before they can decrypt the message. They can do this by running the
gpg --import
command and specifying the file containing your public key.