A .NET app on Linux cannot trust the SQL Server certificate
SSL Provider: The certificate chain was issued by an authority that is not trusted.Short answer
Microsoft.Data.SqlClient 4.0 and later encrypts by default and validates the server certificate. A Linux host or container does not trust a private or self-signed CA, so the login fails. Install the CA on the client, pin the certificate, or fix the name. TrustServerCertificate=true is for isolated development only.
Fix it fast
1Find out which cause you have
Confirm the connection string. If Encrypt is not set, SqlClient 4.0 and later uses Mandatory with certificate validation.
grep -rn "Encrypt\|TrustServerCertificate" appsettings*.json2Match what you see, then jump to its fix
- 1
The error mentions an authority that is not trusted; the same code works on a Windows machine that trusts your CA.The issuing CA is not in the Linux trust storeFix - 2
Chain trust is fine but validation still fails when you connect through an alias or IP address.The name you connect with is not in the certificateFix - 3
The server uses its own generated certificate and the client is a locked-down container.A self-signed server certificate you cannot add to a trust storeFix
- 1
What does the error look like?
SSL Provider: The certificate chain was issued by an authority that is not trusted.
Cause 1 of 3
The issuing CA is not in the Linux trust store
1Check
An enterprise or self-made certificate is not automatically trusted inside a Linux container or on another computer. The CA and any intermediates must be trusted on every client host or container.
sudo ls /etc/ssl/certs/ | grep my-ca2Fix
Install the CA certificate as a PEM file with the .crt extension, then update the trust store.
sudo apt-get install -y ca-certificates
sudo cp my-ca.crt /usr/local/share/ca-certificates
sudo update-ca-certificates3Verify
The PEM file appears in /etc/ssl/certs. Restart the app and connect again with TrustServerCertificate=false.
sudo ls /etc/ssl/certs/ | grep my-caConfirmed by ubuntu.com
Cause 2 of 3
The name you connect with is not in the certificate
1Check
SqlClient compares the Server value with the certificate's subject alternative names.
grep -rn Server= appsettings*.json2Fix
Connect with a name that is in the certificate, or reissue it with the alias. If you must keep the alias, set HostNameInCertificate (SqlClient 5.0 and later) to the name in the certificate.
Server=tcp:sql-alias.example.com,1433;Database=app;Encrypt=true;TrustServerCertificate=false;HostNameInCertificate=sql-server.example.com;3Verify
Open a connection from the app again.
dotnet runConfirmed by learn.microsoft.com
Cause 3 of 3
A self-signed server certificate you cannot add to a trust store
1Check
Export the server certificate from a channel you trust, not from the network connection that is failing.
ls -l /certs/sql-server.cer2Fix
Pin it with the ServerCertificate keyword (SqlClient 5.1 and later), with Encrypt=Mandatory or Strict and TrustServerCertificate=false. Update the pin whenever the certificate is renewed.
Server=tcp:sql.example.com,1433;Database=app;Encrypt=Strict;TrustServerCertificate=false;ServerCertificate=/certs/sql-server.cer;3Verify
A missing, unreadable or mismatched file fails the connection, so a successful open means the pin matched.
dotnet runConfirmed by learn.microsoft.com
How do I stop it coming back?
- Put the CA into your base image at build time so every container trusts it.
- Do not ship TrustServerCertificate=true to production: it encrypts but does not verify the server.
- Plan certificate renewal, and update any pin before the old certificate expires.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
dotnet stops with 'the folder host/fxr does not exist' on Ubuntu
A fatal error occurred. The required library libhostfxr.so could not be found.
This error nearly always means .NET packages came from two different package feeds, usually Ubuntu's own and Microsoft's, and each put files in a different place.
3 causes, each with a fixServers
dotnet says it cannot find any installed .NET SDKs (in Docker or on a server)
A compatible .NET SDK was not found
The dotnet command found a runtime but no SDK that fits.
3 causes, each with a fixServers
AuthenticationException: the remote certificate is invalid in .NET
System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot, NotValidTime
The error lists the chain status flags .NET found.
3 causes, each with a fixServers
Playwright for .NET cannot find the browser inside a Docker container
Microsoft.Playwright.PlaywrightException: Executable doesn't exist
The container has no browser build that matches the Playwright NuGet package your code uses.
3 causes, each with a fixServers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fix