Service Principal Name (SPN) in SQL Server
Service Principal Name (SPN) in SQL Server
Service Principal Name (SPN) in SQL Server
com
Praveen Madupu - +91 98661 30093
Sr SQL Server DBA, Dubai
[email protected]
Service Principal Name (SPN) in SQL Server is a unique identifier for a service instance, used to associate a
service with a domain account. SPNs are essential for enabling Kerberos authentication, which allows clients to
authenticate the SQL Server service without needing to pass passwords over the network.
Kerberos is a secure and efficient authentication protocol often used in environments where performance,
security, and Single Sign-On (SSO) are priorities. Properly configuring an SPN is necessary to enable this
authentication protocol in SQL Server.
1. Pre-requisites
● Domain Account: The SQL Server service should be running under a domain account (not a local system
or network service account) because SPNs are registered in Active Directory.
● Permissions: The domain account used for running SQL Server must have permission to register SPNs
or the person configuring the SPN must have domain administrator rights.
● Fully Qualified Domain Name (FQDN): The SPN needs to be registered with the FQDN or IP address of
the server where SQL Server is installed.
https://www.sqldbachamps.com
2. Determine the SQL Server Service Account
For example:
● DOMAIN\SQLServiceAccount
You need to know the SQL Server instance name and port number to configure the SPN. For the default instance,
SQL Server uses port 1433, but named instances may use dynamic ports.
FROM sys.dm_exec_connections
4. SPN Format
The SPN format for SQL Server differs depending on the protocol (MSSQLSvc) and whether you are using a
default or named instance. The two common formats are:
● Default Instance:
MSSQLSvc/FQDN:1433
MSSQLSvc/HOSTNAME:1433
https://www.sqldbachamps.com
● Named Instance:
MSSQLSvc/FQDN:InstancePort
MSSQLSvc/HOSTNAME:InstancePort
For example, if your SQL Server is running on SQLServer01 and it’s using port 1433 for a default instance, the
SPN would look like:
MSSQLSvc/SQLServer01:1433
MSSQLSvc/SQLServer01.domain.com:1433
MSSQLSvc/SQLServer01:1435
MSSQLSvc/SQLServer01.domain.com:1435
https://www.sqldbachamps.com
Praveen Madupu - +91 98661 30093
Sr SQL Server DBA, Dubai
[email protected]
5. Set the SPN Using setspn Command
Use the setspn command to create, list, or delete SPNs. The syntax for creating SPNs is:
https://www.sqldbachamps.com
setspn -S MSSQLSvc/SQLServer01:1435 DOMAIN\SQLServiceAccount
● -S ensures that the SPN is not duplicated (it will fail if the SPN already exists).
● You can use -A instead of -S if you want to add the SPN without checking for duplicates, but this is not
recommended.
To verify that the SPN was set correctly, use the setspn -L command:
setspn -L DOMAIN\SQLServiceAccount
This will list all SPNs registered for the SQL Server service account. Ensure that the SPNs for both the FQDN and
the hostname are listed with the correct port numbers.
https://www.sqldbachamps.com
Praveen Madupu - +91 98661 30093
Sr SQL Server DBA, Dubai
[email protected]
7. Granting the SQL Service Account Permissions to Register SPNs
If you do not want to manually set SPNs each time or want to automate it, you can grant the SQL Server service
account the permission to register its own SPNs dynamically.
You can use Group Policy to grant the service account permissions to register SPNs. Use the "Read/write
servicePrincipalName" permission for the SQL Server service account.
8. Troubleshooting
https://www.sqldbachamps.com
● Duplicate SPNs: Kerberos authentication fails if there are duplicate SPNs. Run the following command to
check for duplicate SPNs:
setspn -X
Kerberos Validation: To ensure that Kerberos authentication is being used, you can query the current
connections in SQL Server:
SELECT auth_scheme
FROM sys.dm_exec_connections
If Kerberos is configured correctly, the result should display KERBEROS for the auth_scheme.
Removing SPNs: If you need to remove an incorrectly set SPN, use the setspn -D command:
Once the SPN is set and verified, restart the SQL Server service and test Kerberos authentication:
● Use SSMS or another client tool to connect to the SQL Server instance.
● Run the query to check if the auth_scheme is KERBEROS:
SELECT auth_scheme
FROM sys.dm_exec_connections
Summary
https://www.sqldbachamps.com
5. Test Kerberos authentication using SQL Server queries.
Correctly setting up SPN enables Kerberos authentication in SQL Server, which improves security and supports
features like delegation and Single Sign-On (SSO).