The Certificate That Wouldn't Sit Still — or — why SQL Server kept changing its story, and how to make it hold one

A while back I got a message from a data engineer I'll call Marco. It was the kind of message you learn to dread — not angry, just tired. His Fivetran sync from a SQL Server box had failed again overnight. Third time that month. Each time the fix was the same: somebody poked the connection, re-saved the credentials, and it limped back to life until the next time. Nobody knew why. The working theory on his team had calcified into a shrug and the word "Fivetran," said the way you'd say "weather."

I asked him to send me the error. It was a TLS handshake failure. Then I asked the question that cracked it open: "Did anything restart the SQL Server around the times it broke?"

Long pause. "...Patch Tuesday. And a couple of unplanned reboots. Why?"

Because SQL Server, left to its own devices, is lying to Fivetran about who it is. Not maliciously. It just can't keep its story straight.

What's actually going on

If you don't give SQL Server a TLS certificate, it makes one up every time it starts. On service start, if there's no certificate provisioned, the engine generates a fresh self-signed certificate on the spot and uses that to encrypt connections. Restart the service — patch, reboot, failover, a DBA sneezing near the console — and you get a brand new certificate with a brand new fingerprint.

Most clients don't care, because most clients are configured to trust whatever the server waves at them. But a disciplined client — one that validates or pins the certificate it saw last time — takes one look at the new fingerprint and refuses to talk. That's Fivetran. That's why Marco's pipeline died on exactly the nights something bounced the service, and on no other nights. The certificate wouldn't sit still, and Fivetran has standards.

The fix is not to lower Fivetran's standards. The fix is to give SQL Server a certificate of its own — one it keeps — so its story stops changing. We went with a self-signed cert, still no CA (this was an internal box, and standing up a PKI for one pipeline is the kind of yak-shave that eats a quarter), valid for twelve months. One certificate, one fingerprint, one re-trust a year instead of one per reboot.

Let me show you how to do it. It's less work than you'd think.

The rules SQL Server plays by

Before we generate anything, know this: SQL Server is picky about certificates, and when it doesn't like one it rejects it silently and falls back to generating its own. No error. No log line screaming at you. It just quietly goes back to the behavior you're trying to kill, and you're left wondering why your shiny new cert didn't take.

So get these right the first time. They're the same on Windows and Linux:

  1. RSA, 2048-bit or larger.

  2. SHA-256 signature. Not SHA-1, not MD5 — modern Linux OpenSSL runs at security level 2 and will hang up on a weak-signature cert mid-handshake, with an error that looks nothing like the real cause.

  3. Enhanced Key Usage of Server Authentication — the OID 1.3.6.1.5.5.7.3.1. This is the one people miss.

  4. Key Usage of Digital Signature + Key Encipherment.

  5. Subject CN set to the name clients connect to, and a Subject Alternative Name listing every name a client might use — FQDN, short hostname, IP. If Fivetran connects to sql01.contoso.com and your cert says sql01, you've traded a churn problem for a name-mismatch problem.

  6. On Windows specifically, the key has to be a legacy CSP key with KeySpec = AT_KEYEXCHANGE, not a modern CNG/KSP key. More on why that bites you in a second.

I'll use sql01.contoso.com as the hostname throughout. Replace it with the exact name your client dials.

Generating the certificate

You can make this cert on whatever machine is in front of you. Here's all three.

On Linux

OpenSSL, one command. This gives you a PEM certificate and a key file, which is exactly what SQL Server on Linux wants:

openssl req -x509 -nodes -newkey rsa:2048 -sha256 -days 365 \
  -subj '/CN=sql01.contoso.com' \
  -addext "subjectAltName=DNS:sql01.contoso.com,DNS:sql01,IP:10.0.0.5" \
  -addext "extendedKeyUsage=serverAuth" \
  -addext "keyUsage=digitalSignature,keyEncipherment" \
  -keyout mssql.key -out mssql.pem

-days 365 is your twelve months. Use 366 if you want to clear a leap year without thinking about it (but you would never cut it that close, right?)

If the server you're installing onto is Windows, bundle the cert and key into a PFX while you're here:

openssl pkcs12 -export -inkey mssql.key -in mssql.pem -out mssql.pfx

On macOS

macOS ships LibreSSL under the name openssl, and it's perfectly happy with SHA-256. The command is identical to Linux:

openssl req -x509 -nodes -newkey rsa:2048 -sha256 -days 365 \
  -subj '/CN=sql01.contoso.com' \
  -addext "subjectAltName=DNS:sql01.contoso.com,DNS:sql01,IP:10.0.0.5" \
  -addext "extendedKeyUsage=serverAuth" \
  -addext "keyUsage=digitalSignature,keyEncipherment" \
  -keyout mssql.key -out mssql.pem

If your particular build is old enough to choke on -addext, don't fight it — install a current OpenSSL and call it by its full path:

brew install openssl@3
$(brew --prefix openssl@3)/bin/openssl req -x509 -nodes -newkey rsa:2048 -sha256 -days 365 \
  -subj '/CN=sql01.contoso.com' \
  -addext "subjectAltName=DNS:sql01.contoso.com,DNS:sql01,IP:10.0.0.5" \
  -addext "extendedKeyUsage=serverAuth" \
  -addext "keyUsage=digitalSignature,keyEncipherment" \
  -keyout mssql.key -out mssql.pem

On Windows

Here's where I'll save you an afternoon. The native tool is PowerShell's New-SelfSignedCertificate, and it's genuinely the nicest option when SQL Server itself runs on Windows, because it drops the finished certificate straight into the machine store with the right EKU already set.

But the default behavior creates a CNG/KSP key, and older SQL Server engines won't touch those — remember that AT_KEYEXCHANGE rule. So we force a legacy CSP provider and the right KeySpec. This is the single detail that turns "why won't it show up in Configuration Manager" into a non-event:

$cert = New-SelfSignedCertificate `
  -Type SSLServerAuthentication `
  -Subject "CN=sql01.contoso.com" `
  -DnsName "sql01.contoso.com","sql01","10.0.0.5" `
  -KeyAlgorithm RSA -KeyLength 2048 -HashAlgorithm SHA256 `
  -KeySpec KeyExchange `
  -Provider "Microsoft RSA SChannel Cryptographic Provider" `
  -KeyExportPolicy Exportable `
  -NotBefore (Get-Date) -NotAfter (Get-Date).AddMonths(12) `
  -CertStoreLocation "Cert:\LocalMachine\My"

$cert.Thumbprint   # write this down

-Type SSLServerAuthentication is doing quiet, heavy lifting: it sets the Server Authentication EKU and the Digital Signature + Key Encipherment usages for you. And because the cert lands in LocalMachine\My already, you get to skip the import step below entirely.

Installing it into SQL Server

If SQL Server runs on Windows

1. Get the cert into the Local Computer store. Skip this if you generated it with PowerShell — it's already there. Otherwise, import the PFX:

Import-PfxCertificate -FilePath .\mssql.pfx `
  -CertStoreLocation Cert:\LocalMachine\My `
  -Password (Read-Host -AsSecureString)

Or GUI: certlm.msc → Personal → Certificates → All Tasks → Import.

2. Let the SQL Server service account read the private key. This is the step everyone forgets, and its symptom — the service starts but the cert silently doesn't load — sends people down the wrong rabbit hole for hours. Find the service account in services.msc (it's usually something like NT Service\MSSQLSERVER), then open certlm.msc, right-click your certificate, pick All Tasks → Manage Private Keys, and give that account Read. That's it.

3. Bind the certificate to the instance. Open SQL Server Configuration Manager → SQL Server Network Configuration, right-click Protocols for <your instance>, choose Properties, go to the Certificate tab, and select your cert from the dropdown. (On SQL Server 2019 and up there's also an Import button right there if it isn't showing.) If you want to force every client to encrypt, flip over to the Flags tab and set ForceEncryption to Yes.

If the dropdown refuses to cooperate — older builds sometimes do — you can set the thumbprint by hand in the registry. Lowercase, no spaces:

HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\<InstanceID>\MSSQLServer\SuperSocketNetLib\Certificate

4. Restart the SQL Server service.

5. Confirm it actually took. Check the SQL Server ERRORLOG for a line like "The certificate [Cert Hash(sha1) …] was successfully loaded for encryption" — that's the sentence you want to see. Then from a client:

SELECT session_id, encrypt_option, protocol_type
  FROM sys.dm_exec_connections
 WHERE session_id = @@SPID;

encrypt_option should read TRUE.

If SQL Server runs on Linux

1. Drop the files where they belong and lock them down. SQL Server won't load a key it can't read — and it also won't load one that's readable by the whole world. Both failures are silent, naturally:

sudo chown mssql:mssql mssql.pem mssql.key
sudo chmod 600 mssql.pem mssql.key
sudo mv mssql.pem /etc/ssl/certs/
sudo mv mssql.key /etc/ssl/private/

2. Point mssql-conf at them and restart. For SQL Server 2022 and earlier:

sudo systemctl stop mssql-server
sudo /opt/mssql/bin/mssql-conf set network.tlscert      /etc/ssl/certs/mssql.pem
sudo /opt/mssql/bin/mssql-conf set network.tlskey       /etc/ssl/private/mssql.key
sudo /opt/mssql/bin/mssql-conf set network.tlsprotocols 1.2
sudo /opt/mssql/bin/mssql-conf set network.forceencryption 1
sudo systemctl restart mssql-server

SQL Server 2025 turns on TLS 1.3 by default, so you drop the tlsprotocols line:

sudo systemctl stop mssql-server
sudo /opt/mssql/bin/mssql-conf set network.tlscert      /etc/ssl/certs/mssql.pem
sudo /opt/mssql/bin/mssql-conf set network.tlskey       /etc/ssl/private/mssql.key
sudo /opt/mssql/bin/mssql-conf set network.forceencryption 1
sudo systemctl restart mssql-server

Set forceencryption to 0 if you'd rather leave encryption at the client's discretion; TLS still gets negotiated either way.

3. Confirm. The successful-load line shows up in /var/opt/mssql/log/errorlog, and the same sys.dm_exec_connections query works here too.

Don't forget the client

The server now presents a stable, self-signed certificate. Fivetran still has to agree to trust it, because there's no CA vouching for it. In the connector, turn on Require TLS and either hand Fivetran the certificate to trust — upload or paste the mssql.pem, the public certificate, and never ever the key file — or enable trust-server-certificate if skipping chain validation is acceptable for the box. Make sure the hostname in the connector matches the CN/SAN on the cert. Get those lined up and the handshake just works.

The part you'll thank yourself for

There's one catch, and it's the whole reason to write it down: this certificate expires in twelve months. That's the deal we made — a stable cert, but a self-signed one with a finite life. A year from now, on some unremarkable Tuesday, Marco's pipeline breaks exactly the way it used to, and if nobody remembers why, the shrug and the word "Fivetran" come right back.

So the last command in this procedure doesn't touch SQL Server at all. It asks the certificate when it plans to die, and schedules a reminder 30 days ahead of that — a reminder whose instructions are to come back and re-read this post, rotate the cert, and then run this same command again. It is, give or take, a shell quine with separation anxiety:

# Ask the cert when it dies; schedule Future You 30 days before the funeral.
EXPIRY=$(openssl x509 -enddate -noout -in mssql.pem | cut -d= -f2)
REMIND=$(date -d "$EXPIRY -30 days" '+%M %H %d %m')   # -> "M H DoM Mon"

( crontab -l 2>/dev/null
  echo "$REMIND *  echo 'Renew sql01.contoso.com cert; " \
       "see https://jameshunt.us/writings/the-certificate-that-wouldnt-sit-still' " \
       "| mail -s 'ACHTUNG: the certificate will not sit still much longer' $EMAIL"
) | crontab -

Marco's pipeline has been quiet ever since. The nice thing about a server that stops changing its story is that everyone else gets to stop listening so hard.

James Hunt (the avatar)

James (@iamjameshunt) works on the Internet, spends his weekends developing new and interesting bits of software and his nights trying to make sense of research papers.

Currently exploring Kubernetes, as both a floor wax and a dessert topping.

Liked That? Try These:

The Ordered Mind

The Ordered Mind

You Can't Prompt a Padlock

You Can't Prompt a Padlock

Silly Docker Tricks

Managing the X11 Clipboard

Dockerless Docker with Runc

Putting Docker Compose on top of BOSH