在CentOS上设置邮件服务器时,确保其安全性至关重要。以下是一些关键的安全设置步骤和最佳实践:
/etc/passwd
文件,检测并锁定不必要的超级账户。adm
, lp
, sync
等。/etc/login.defs
文件来强制执行这些要求。awk -F ":" '$2 =="" {print $1}' /etc/shadow
chattr
命令给 /etc/passwd
, /etc/shadow
, /etc/group
, 和 /etc/gshadow
文件加上不可更改属性,以防止未授权访问。sudo yum update -y
sudo yum install postfix dovecot mysql-server dovecot-mysql -y
/etc/postfix/main.cf
文件,设置主机名、域名、邮件服务器的IP地址、允许所有IP地址通过SMTP连接到本地、启用SASL认证、启用TLS加密等。myhostname = mail.example.com
mydomain = example.com
inet_interfaces = all
inet_protocols = ipv4
home_mailbox = Maildir/
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_tls_cert_file = /etc/pki/tls/certs/localhost.crt
smtpd_tls_key_file = /etc/pki/tls/private/localhost.key
smtpd_use_tls = yes
smtp_tls_security_level = encrypt
/etc/dovecot/dovecot.conf
文件,设置协议为 imap
, pop3
, lmtp
,禁用明文认证,设置邮件存储位置为 maildir:
。protocols = imap pop3 lmtp
disable_plaintext_auth = no
mail_location = maildir:~/Maildir
firewalld
或 iptables
配置防火墙规则,限制对服务器的访问,只允许必要的端口对外开放。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
sudo yum install certbot -y
sudo certbot certonly --standalone -d mail.example.com
/etc/postfix/main.cf
文件,确保以下行存在并正确指向你的证书文件:smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem
通过实施上述措施,可以显著提高CentOS邮件服务器的安全性,减少受到网络攻击的风险。