Skip to content
  • There are no suggestions because the search field is empty.

How to rotate a DKIM key

To rotate a DKIM key, publish the new key under a new selector, wait until it resolves, switch signing to it, confirm new mail passes with the new selector, and keep the old key published for at least a week before you remove or revoke it. The one thing not to do is replace the key at the selector you're already signing with. Mail that's still in transit, or that a receiver checks later, would then fail against the wrong key.

Why rotate DKIM keys at all

Rotation limits how long a cracked or stolen private key stays useful. It also keeps the procedure practiced, so an emergency rotation isn't the first time anyone's done it. A misappropriated private key is one of DKIM's security risks, and keys can be replaced on a regular basis.

How often?

Industry practice is to rotate DKIM keys at least every six months. The DKIM standard itself sets no schedule. So six months is best practice, not a requirement. If your security team already has a key-rotation policy, agree the schedule with them.

Why the old key has to stay

Receivers don't always check a signature the moment a message arrives. Verifiers can choose to defer validation, perhaps until the message is actually read, so the old public key should be retained for a reasonable validation interval before being removed. Messages queued for retry or delayed in transit also arrive after you've switched.

That's also why you use a new selector. Signers are ill-advised to reuse selectors for new keys, and reuse is strongly discouraged, because old messages fail re-validation and receivers may still hold stale cached values.

If you get this wrong, the damage isn't limited to DKIM. Forwarded mail usually loses SPF on the way, so aligned DKIM is often the only thing keeping it passing DMARC (DKIM and mailing lists or forwarders).

Step by step: rotating a key you manage yourself

This is the usual workflow for TXT keys you publish and a mail system you control.

  1. Generate a new key pair. Use 2048-bit RSA if your DNS host can hold it (1024-bit vs 2048-bit DKIM keys).
  2. Publish the new public key under a new selector. A dated name makes the scheme obvious, for example moving from s2026a to s2026b. Leave the current selector alone. This is a schematic, not a record to copy:

s2026a._domainkey.example.com TXT "v=DKIM1; k=rsa; p=<current key>" (still signing) s2026b._domainkey.example.com TXT "v=DKIM1; k=rsa; p=<new key>" (new)

  1. Wait until the new record resolves publicly. Switching early means the first messages fail.
  2. Switch signing to the new private key and selector.
  3. Verify. Send to an external mailbox and confirm dkim=pass with s=s2026b in Authentication-Results. Your DMARC aggregate reports show the selector per source too (A field-by-field walk-through of a DMARC aggregate report).
  4. Keep the old public key unchanged for an overlap period, typically a minimum of seven days and up to 30 days.
  5. Retire the old key. You can delete the record or revoke it by leaving p= empty:

s2026a._domainkey.example.com TXT "v=DKIM1; p="

There's no defined semantic difference between a revoked key and a removed key. Revoking and keeping the selector name makes it clear the key was retired on purpose. 8. Audit about a week later. Compare the live d= and s= values in your mail with your selector list.

Pre-publish the next key

It's also good practice to always have the next public key already in DNS. Then an emergency rotation needs only the mail admin, not a DNS change request. Who holds which part of this job is covered in Who usually owns SPF, DKIM, and DMARC.

Emergency: the private key is compromised

Don't wait out an overlap period. Revoke the compromised selector right away with an empty p=. A revoked key is treated as a failed signature. Switch signing to your pre-published key. Accept that some mail already signed with the old key will fail DKIM. That's the trade-off for shutting the key down.

Rotating DKIM keys in Microsoft 365

Microsoft 365 uses two CNAMEs, selector1._domainkey and selector2._domainkey, and only one selector is active at a time. Rotate DKIM keys in the Defender portal, or Rotate-DkimSigningConfig in PowerShell, switches to the other one.

It isn't instant. It takes four days (96 hours) for the new private key to start signing messages, and you can't start another rotation while one is in progress. You can raise the key size to 2048 during a rotation with -KeySize 2048.

Both CNAMEs have to exist. Microsoft lists a missing selector2._domainkey record as a common mistake. Delete it because it "isn't used" and the next rotation fails. Setup screens are in DMARC for Microsoft 365.

Rotating a DKIM key in Google Workspace

Google Workspace doesn't describe a separate DKIM rotation procedure. In practice, rotation means generating a new record, entering a different prefix (selector) if the current one is in use, publishing it, waiting (up to 48 hours), and then using Start authentication. Google Workspace doesn't say exactly when the old key stops signing, so confirm the new s= in a real message rather than assume. Keep the old record published through the overlap. Setup screens are in DMARC for Google Workspace.

When your platform hosts the key

If a sending platform had you publish CNAMEs pointing to keys it hosts, the platform holds the keys and can rotate them behind those names. That's key delegation via CNAME. Don't edit or delete those CNAMEs unless the platform tells you to. If you change keys too quickly or frequently, DNS may not be able to authenticate your mail because the former key may already be invalidated.

Mistakes worth avoiding

  • Switching signing before the new record resolves.
  • Pasting the new key over the live selector instead of using a new one.
  • Deleting the old record the moment the new one works.
  • Reusing last year's selector name.
  • Rotating one service and forgetting the others. Each sender has its own selector, so keep an inventory (DKIM selectors and DNS records).
  • Deleting Microsoft's selector2 CNAME.

Free DMARC account

Turn raw DMARC reports into a readable dashboard

Point your rua address to our platform and read the results by sender and source instead of opening XML files.

  • Results grouped by sending source
  • SPF, DKIM and alignment results per sender
  • The original XML reports are still there to download

Create a free DMARC accountTalk to an expert

FAQ

How often should DKIM keys be rotated?

Industry practice is at least every six months. The DKIM standard itself sets no schedule.

Can I just update the key in my current record?

Use a new selector instead. Reusing a selector makes in-flight and re-checked mail fail.

How long do I keep the old key?

Long enough for delayed and re-checked mail, typically 7 to 30 days.

Is removing the old key different from revoking it?

Not to receivers. There's no defined difference. Revoking with an empty p= just leaves a visible record that the key was retired.

How do I know the rotation worked?

New messages show dkim=pass with the new s=, and your DMARC aggregate reports show the new selector passing for that source.