Linux Mail Server Setup Centos Centos 7 Github

How do you setup a Linux mail server on CentOS 7 and manage configurations with GitHub? The process involves installing and configuring key components such as Postfix, Dovecot, and MySQL/MariaDB, ensuring proper DNS records are in place, securing the server with SSL/TLS, and optionally leveraging GitHub for version control of configuration files. Using GitHub is particularly valuable for system administrators who need to manage multiple servers or maintain configuration history for auditing and recovery. purposes.

In this article, we will walk step by step through the Linux mail server setup on CentOS 7, while also explaining how to maintain configurations via GitHub for better reliability and collaboration.

Why Use CentOS 7 for a Mail Server?

CentOS 7 has been a top Linux operating system for running servers for enterprise levels for decades. Its strengths are:

  • Stability: Built upon Red Hat Enterprise Linux (RHEL), offering strong long-term support.
  • Compatibility: Compatible perfectly with Postfix, Dovecot, MySQL, and other critical mail components.
  • Community Support: Extensive guides, GitHub repositories, and open-source scripts are available.
  • Security Updates: Enterprise-grade patching ensures strong reliability for email services.

Key Components of a Mail Server Setup

When building a mail server on CentOS 7, you’ll typically configure the following:

  1. Postfix – Handles sending and receiving mail (Mail Transfer Agent).
  2. Dovecot – Provides IMAP and POP3 services for email retrieval.
  3. MariaDB/MySQL – Stores virtual domains, users, and authentication data.
  4. SpamAssassin & ClamAV – Protect against spam and viruses.
  5. SSL/TLS Certificates – Secure email transmission.
  6. GitHub Integration – Store configuration files and scripts for version control and collaboration.

Step-by-Step Setup of Linux Mail Server on CentOS 7

1. Update Your System

Before installing packages, update CentOS 7:

bash Copy code
sudo yum update -y

2. Set Hostname and DNS Records

Assign a hostname for your mail server:

bash Copy code
hostnamectl set-hostname mail.example.com

Update your DNS records:

  • A Record: mail.example.com → Server IP
  • MX Record: Points to mail.example.com
  • SPF Record: v=spf1 mx ~all
  • DKIM/DMARC: Recommended for email authentication.

3. Install Postfix

Postfix is the default MTA for CentOS. Install it using:

bash   Copy code
sudo yum install postfix -y
sudo systemctl enable postfix
sudo systemctl start postfix

Edit the configuration file:

bash   Copy code
sudo nano /etc/postfix/main.cf

Key settings:

ini   Copy code
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

Reload Postfix:

bash   Copy code
sudo systemctl restart postfix

4. Install and Configure Dovecot

Dovecot provides IMAP/POP3 support:

bash   Copy code
sudo yum install dovecot -y
sudo systemctl enable dovecot
sudo systemctl start dovecot

Edit /etc/dovecot/dovecot.conf:

ini   Copy code
protocols = imap pop3
mail_location = maildir:/var/mail/vhosts/%d/%n

Restart Dovecot:

bash   Copy code
sudo systemctl restart dovecot

5. Create Virtual Mail Users and Domains

For large-scale setups, use MariaDB/MySQL for user authentication. Example MariaDB installation:

bash   Copy code
sudo yum install mariadb-server mariadb -y
sudo systemctl enable mariadb
sudo systemctl start mariadb

Secure MariaDB:

mysql_secure_installation

Then create databases for storing mail user information.

6. Enable Firewall and Ports

Open necessary ports:

bash   Copy 
sudo firewall-cmd --permanent --add-service=smtp
sudo firewall-cmd --permanent --add-service=imap
sudo firewall-cmd --permanent --add-service=pop3
sudo firewall-cmd --reload

7. Secure with SSL/TLS

Install Let’s Encrypt for free SSL certificates:

bash   Copy code
sudo yum install certbot -y
certbot certonly --standalone -d mail.example.com

Configure Postfix & Dovecot to use SSL certificates.

8. Add Spam and Antivirus Filters

Install SpamAssassin & ClamAV to prevent junk mail and malware.

bash   Copy code
sudo yum install spamassassin clamav -y
systemctl enable spamassassin
systemctl start spamassassin

Managing Mail Server Configurations with GitHub

GitHub is a powerful tool for storing, tracking, and sharing server configurations. Here’s how to incorporate it into your daily tasks:

1. Create a Private GitHub Repository

  • Store configuration files like /etc/postfix/main.cf and /etc/dovecot/dovecot.conf.
  • Keep sensitive data (passwords, certificates) excluded using .gitignore.

2. Clone Repo on Server

bash   Copy code
git clone https://github.com/yourusername/mailserver-config.git /etc/mailserver-config

3. Track Changes

After modifying configurations:

bash   Copy code
git add .
git commit -m "Updated Postfix and Dovecot configs"
git push origin main

4. Automation with GitHub Actions

Use GitHub Actions or CI/CD tools to automatically deploy configuration updates to multiple mail servers.

Example .github/workflows/deploy.yml:

yaml   Copy code
name: Deploy Mail Configs
on: [push]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Sync Configs
run: rsync -avz ./ [email protected]:/etc/

Best Practices for Running a Mail Server

  • Regular Backups: Backup /var/mail, databases, and configuration files.
  • Monitor Logs: Use tools like journalctl -xe and tail -f /var/log/maillog.
  • Implement DKIM & DMARC: Strengthen email authentication.
  • Limit Open Relays: Ensure Postfix is not an open relay.
  • Use GitHub for Version Control: Enables rollback and team collaboration.

Conclusion

To install a Linux mail server on a CentOS 7 system, you will need Postfix, Dovecot, databases, DNS records, and extra security. Linked with GitHub, it provides better control, collaboration, and critical configuration version history. The end result is a reliable, protected, and easily manageable email system for enterprises and institutions.

Using CentOS 7 together with GitHub configuration management greatly enhances server deployment efficiency for system administrators managing multiple servers and developers building custom email workflows.