Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
VGSources
Blog

How to Configure DKIM with Postfix on a Linux VPS

Connect Postfix to OpenDKIM, publish the matching selector TXT record, protect the private key and verify signatures with opendkim-testkey and delivered headers.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To sign outgoing mail from Postfix, run OpenDKIM as a Milter and connect Postfix to it. The selector, domain, private-key path, OpenDKIM socket and DNS TXT record must describe the same key. Publish the public key at selector._domainkey.yourdomain, keep the private key readable only by OpenDKIM, configure both Postfix Milter parameters, then verify alignment with opendkim-testkey and a delivered message.

What this setup does

DKIM (DomainKeys Identified Mail) adds a cryptographic signature to an outgoing message. A receiving server retrieves your public key from DNS, hashes the signed headers and body, and checks the signature. A passing result helps the recipient verify that the message was authorized by the domain shown in the signature and that signed content was not changed in transit.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Postfix does not create that signature by itself in this arrangement. It hands each message to OpenDKIM through the Milter protocol. OpenDKIM reads the configured private key, creates the DKIM-Signature header, and returns the message to Postfix for delivery. Postfix’s Milter documentation describes this integration as a way to add applications that verify authenticity or digitally sign mail.

This guide covers outbound signing on Debian-family Linux VPS systems. Package names, service users, file locations, chroot settings and service-manager behavior can differ on other distributions, so confirm the installed package documentation before copying paths verbatim.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Prerequisites and the values you must keep aligned

Have all of these ready before generating a key:

  • A domain whose DNS zone you can edit.
  • A working Postfix installation on a Linux VPS.
  • A stable server hostname and functioning outbound SMTP configuration. The commonly cited DigitalOcean procedure assumes these are already complete.
  • A domain and selector name you will use consistently. This guide uses yourdomain.example and mail.

Five values form one DKIM identity. Changing one without changing the others causes a lookup or verification failure.

Component Example Where it is used
Signing domain yourdomain.example OpenDKIM Domain, key generation and the DNS owner name
Selector mail OpenDKIM Selector, the signature’s s= value and DNS
Private key /etc/dkimkeys/mail.private Read locally by OpenDKIM; never publish it
Public key The p= value from mail.txt Published in a DNS TXT record
Milter socket inet:8891@localhost OpenDKIM listener and Postfix Milter settings

1. Install OpenDKIM and its utilities

On a Debian-family system, install the signer and test tools:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt install opendkim opendkim-tools

The Debian packages provide the OpenDKIM daemon plus utilities such as opendkim-genkey and opendkim-testkey. Do not proceed until the package installation completes and the service account created by your distribution is known; the examples below use the usual opendkim account.

2. Generate a selector key pair

Create the directory

sudo mkdir -p /etc/dkimkeys

Choose a selector that identifies this key, such as mail or a rotation label such as 2026. Selectors let you publish a replacement key while the old selector remains available for messages already in transit.

Generate the private and public files

sudo -u opendkim opendkim-genkey -D /etc/dkimkeys -d yourdomain.example -s mail

This creates a private key (normally mail.private) and a DNS-ready public-key file (normally mail.txt). Debian documents a 2048-bit default. That is a package default, not a universal requirement. If your DNS provider cannot accept the resulting TXT length, the Debian Handbook documents generating a 1024-bit key with -b 1024; use that only when the provider limitation and your security policy justify the smaller key.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Protect the private key

sudo chown opendkim:opendkim /etc/dkimkeys/mail.*

The Debian Handbook shows ownership by opendkim. Preserve restrictive modes in your distribution’s package layout so ordinary users cannot read the private file. OpenDKIM’s RequireSafeKeys behavior can reject keys with unsafe ownership or permissions. Never put the private key in DNS, a web directory, a ticket, or a repository.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Publish the public key in DNS

Use the exact owner name

Open /etc/dkimkeys/mail.txt and create a TXT record with this owner name:

mail._domainkey.yourdomain.example

Copy the complete v=DKIM1; ...; p= value generated in that file. The generated text may contain formatting intended for DNS; retain the entire public-key value, including every character after p=.

Handle long TXT values correctly

Some DNS interfaces display a long value as multiple quoted strings. That is valid when the provider concatenates the strings for DNS responses. Do not omit a segment or add explanatory text. The Debian example uses a 3600-second TTL and identifies an RSA/SHA-256 record; 3600 seconds is an example, not a mandatory TTL.

DNS systems may impose 255-character limits on an individual text string. If your provider enforces that limit, use its supported TXT-string splitting interface. A 2048-bit public key commonly needs splitting at the presentation layer; never split or alter the base64 characters themselves. If the provider cannot represent the key even with supported splitting, consult its documentation and consider the documented 1024-bit generation option only after evaluating the security trade-off.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

4. Configure OpenDKIM

Single domain and single key

For one domain and one selector, the essential settings are:

Domain    yourdomain.example
Selector  mail
KeyFile   /etc/dkimkeys/mail.private
Socket    inet:8891@localhost

Place equivalent directives in the configuration file used by your distribution, commonly under /etc/opendkim.conf. The names are case-insensitive in normal OpenDKIM configuration, but keep the spelling shown by your package documentation.

The TCP socket above listens on localhost port 8891. A local UNIX socket is also valid, for example a socket path under /run/opendkim, but Postfix must be able to reach that path. If Postfix runs chrooted, the socket has to exist inside the chroot-visible filesystem or the chroot must be adjusted. A mismatch between the configured protocol (inet: versus a UNIX path), address or port prevents signing.

Multiple domains or selectors

When one static KeyFile is no longer enough, use KeyTable and SigningTable. KeyTable maps a key name to a domain, selector and private-key path; SigningTable chooses that key from the sender identity. OpenDKIM’s manual states that defining KeyTable overrides KeyFile, and that Selector is ignored when a KeyTable is defined.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Design Best fit Operational consideration
One Domain, Selector and KeyFile One sending domain and one active key Few files and the simplest troubleshooting path
KeyTable plus SigningTable Several domains, identities or rotating selectors More flexible mapping; every table entry and DNS name must match

5. Connect Postfix to the OpenDKIM Milter

Edit /etc/postfix/main.cf and add the socket settings:

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
smtpd_milters = inet:localhost:8891
non_smtpd_milters = $smtpd_milters
milter_default_action = accept

smtpd_milters applies to mail received through an SMTP session. non_smtpd_milters applies to locally generated mail and other mail injected without an SMTP server session, such as messages submitted by a local application. Setting only the first parameter is the usual reason a locally generated message has no signature.

milter_default_action = accept tells Postfix to accept mail when the Milter is temporarily unavailable. Debian recommends this behavior so a signer outage does not discard mail. It also means a message can leave unsigned during an OpenDKIM failure, so monitor the service and authentication results rather than treating this setting as a substitute for reliability.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If you use more than one Milter, preserve the existing space-separated list and add the OpenDKIM endpoint in the syntax required by your Postfix version. The socket in Postfix must exactly match the listener configured in OpenDKIM.

Restart and reload

sudo systemctl restart opendkim
sudo systemctl reload postfix

Restarting OpenDKIM ensures its key and socket settings are active. Reloading Postfix applies main.cf without unnecessarily stopping the mail queue. If your distribution uses another service manager, use its equivalent operations.

6. Validate the key and send a controlled test

Run the DNS/key alignment test

sudo opendkim-testkey -d yourdomain.example -s mail -vvv

Use exactly the domain and selector configured above. A successful result indicates that OpenDKIM can find the DNS TXT record and that the local key setup is aligned according to Debian’s documentation. A verbose failure usually identifies whether the problem is a lookup, selector, domain, path or permission issue.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Inspect a delivered message

Send a message to a mailbox you control, preferably at a different provider. View the raw message source, not only the simplified mailbox view. You should see a DKIM-Signature header containing values such as d=yourdomain.example and s=mail, followed by an Authentication-Results header reporting dkim=pass.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The signature’s d= and s= values tell you which DNS name the recipient queried. Compare them character-for-character with the owner name you published. A message can contain a signature while still failing if the recipient cannot retrieve the matching key or if an intermediary changed signed content.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choosing sockets, canonicalization and domain scope

These are design decisions rather than mandatory changes to the basic recipe.

Axis Option When to choose it Trade-off
Transport to OpenDKIM TCP localhost socket (inet:8891@localhost) Simple package defaults and clearly separated service endpoints Requires a listening port and matching address; confirm local firewall policy
Transport to OpenDKIM UNIX socket Local-only communication and no TCP listener Directory ownership, path visibility and Postfix chroot handling become critical
Canonicalization simple Strict preservation of signed headers and body formatting More vulnerable to harmless whitespace or line-ending changes by intermediaries
Canonicalization relaxed Mail likely to pass through systems that normalize whitespace or header folding Allows limited normalization; it does not protect against arbitrary content edits
Domain scope One domain and selector A single controlled sending identity Each additional domain or rotation requires a deliberate configuration change
Domain scope KeyTable/SigningTable Multiple domains, sender identities or active selectors More mappings to audit and more DNS records to maintain

OpenDKIM’s manual defines the canonicalization controls and table behavior. Choose a policy that matches the transformations your mail will encounter; changing canonicalization after deployment changes the signature behavior and should be followed by a new end-to-end test.

Troubleshooting by symptom

opendkim-testkey reports “key not secure” or a lookup failure

  • Confirm the TXT owner name is exactly mail._domainkey.yourdomain.example, including the selector and domain.
  • Query DNS using a DNS diagnostic tool and check that the complete p= value is returned.
  • Check that the command’s -d and -s values match OpenDKIM’s Domain and Selector.
  • Review private-key ownership and mode. Strict RequireSafeKeys settings reject unsafe files.

There is no signature on locally generated mail

Check that non_smtpd_milters = $smtpd_milters is present in main.cf, then reload Postfix. Locally generated mail follows a different Postfix path from SMTP-injected mail, so a working smtpd_milters setting alone is insufficient.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

OpenDKIM cannot read the private key

  • Verify the path in KeyFile exists and is readable by the account running OpenDKIM.
  • Check every parent directory for execute permission by that account.
  • Confirm the owner and mode after package upgrades or manual copies.
  • If the daemon is restricted by a chroot or other service sandbox, make the key available in the permitted path without broadening access to other users.

Postfix cannot connect to OpenDKIM

  • Ensure OpenDKIM is running and listening on the same protocol, address and port named in Postfix.
  • For a UNIX socket, check socket-file ownership and whether Postfix’s chroot can see the directory.
  • For the TCP example, confirm the listener is bound to localhost port 8891 and that no local policy blocks it.
  • Inspect the OpenDKIM and Postfix service logs immediately after sending a test message; the first connection error usually identifies the mismatched endpoint.

The signature passes initially but fails after forwarding

Mailing-list software and other intermediaries can rewrite signed headers or body content. Debian specifically warns that these changes can invalidate DKIM. Compare the original delivered message with the forwarded copy and identify which system altered it. You cannot repair a signature after an intermediary has changed signed data; choose compatible canonicalization, avoid signing headers a known intermediary rewrites when policy permits, or accept that forwarded copies may fail.

The DNS value appears truncated

Check whether the provider split the TXT value into multiple quoted strings and whether every string is present in the DNS response. Do not paste only the first visual line. If the provider has a hard per-string limit, use its documented splitting mechanism; only then consider the documented 1024-bit key alternative, after weighing the reduced key size.

Security and maintenance practices

  • Back up configuration and private keys securely, separately from public DNS data. A stolen private key lets an attacker sign mail for the selector until you revoke it.
  • Use a new selector for planned key rotation. Publish the new TXT record, deploy the matching private key and configuration, test a message, then retire the old DNS record only after messages signed with it have aged out.
  • Limit shell and file access to administrators who need it. The private-key directory should not be writable by the web server or untrusted applications.
  • Monitor for unsigned mail and authentication failures. With milter_default_action = accept, temporary OpenDKIM outages can allow delivery without a signature.
  • Keep DNS TTL, selector inventory and table entries documented so a future administrator can identify which key signs which domain.

Final verification checklist

  1. Postfix is installed, accepts outbound mail and has a stable hostname.
  2. OpenDKIM and opendkim-tools are installed.
  3. The private key exists at the configured path, is owned by the OpenDKIM service account and has restrictive permissions.
  4. The public key is published at the exact selector._domainkey.domain owner name.
  5. The OpenDKIM socket is listening and reachable from Postfix’s execution context.
  6. Both smtpd_milters and non_smtpd_milters point to that socket.
  7. opendkim-testkey -d yourdomain.example -s mail -vvv succeeds.
  8. A raw delivered message contains a matching DKIM-Signature and reports dkim=pass.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.