Environment:
cPanel server (VPS or Dedicated Server)
Access Required: SSH root access
Introduction
SPF (Sender Policy Framework) and DKIM (DomainKeys Identified Mail) help prevent email spoofing by authenticating outgoing emails. Enabling these for all accounts improves email deliverability and security.
How to Enable SPF and DKIM for All Users
- Login to your server via SSH as root:
ssh root@your-server-ip
- Run the following command to install SPF and DKIM for every cPanel account:
for user in `ls -A /var/cpanel/users` ; do /usr/local/cpanel/bin/dkim_keys_install $user && /usr/local/cpanel/bin/spf_installer $user ; done
What this does:- Iterates over all existing cPanel usernames.
- Installs DKIM keys using
dkim_keys_install
. - Installs SPF records using
spf_installer
.
Verify DNS Zone Changes
To confirm the changes:
cat /var/named/yourdomain.com.db | grep TXT
Replace yourdomain.com
with the actual domain name.
Notes
- Ensure DNS is managed on the same server. If using external DNS (e.g., Cloudflare), you’ll need to manually copy the generated records.
- These tools are part of cPanel and require a properly licensed and configured installation.
By running the above, all existing accounts will have SPF and DKIM configured automatically.