The cart is empty

In today's digital world, security and privacy protection are paramount. One effective way to secure email communication is by encrypting email content. In this article, we will look at a step-by-step guide on configuring automatic email encryption when sending emails from the Postfix mail server on CentOS 7 using GNU Privacy Guard (GPG).

Prerequisites

Before we begin, make sure you have:

  • Installed and functional Postfix on CentOS 7.
  • Installed GPG. If you don't have GPG installed, you can install it using the command yum install gnupg.

Step 1: Generating GPG Keys

The first step is to generate a GPG key pair (public and private key) for the user under which Postfix runs, typically postfix or root. Log in to the terminal as this user and run the following command:

gpg --gen-key

During the key creation process, you will be prompted to enter several pieces of information, such as name, email, and key passphrase. These pieces of information help identify the key and secure the private key with a passphrase.

Step 2: Configuring Postfix

To have Postfix automatically encrypt outgoing emails, you need to write a script that will be run as a filter for outgoing emails. This script will be responsible for encrypting the email using the recipient's public key.

Create a script file /usr/local/bin/postfix-gpg-encrypt.sh with the following content:

#!/bin/bash

RECIPIENT_EMAIL="$1"

gpg --batch --trust-model always --output - --encrypt --recipient "$RECIPIENT_EMAIL"

Don't forget to grant execution rights to the script:

chmod +x /usr/local/bin/postfix-gpg-encrypt.sh

Next, you need to modify the Postfix configuration (/etc/postfix/main.cf) and add a new pipeline path that includes your encryption script:

smtpd_sender_restrictions = check_sender_access pcre:/etc/postfix/gpg_encrypt

In /etc/postfix/gpg_encrypt, define rules for encryption, for example:

/.+/ FILTER gpg-encrypt:/usr/local/bin/postfix-gpg-encrypt.sh

Step 3: Testing

Once the configuration is complete, it's a good practice to test the entire system. Try sending an email to an address with a configured public key and verify that it was encrypted correctly.

 

Configuring automatic email encryption in Postfix on CentOS 7 using GPG is a process that requires careful preparation and configuration. The above steps provide a basic guide on achieving email communication security through encryption. It's important to note that the proper functioning of this solution depends on the correct configuration and mutual compatibility of public keys between the sender and recipient.