다음을 통해 공유


인증 유형이 Kerberos인지 확인하는 방법

이 문서에서는 Microsoft SQL Server에 연결할 때 사용되는 인증 유형을 확인하는 데 도움이 되는 단계별 지침을 제공합니다. 테스트 중인 SQL Server 인스턴스가 설치된 서버가 아닌 클라이언트 컴퓨터에서 단계를 실행해야 합니다. 그렇지 않으면 Kerberos가 올바르게 구성된 경우에도 출력의 auth_scheme 값은 항상 NTLM이 됩니다. 이는 Windows 2008에서 추가된 서비스별 SID 보안 강화 기능 때문에 발생합니다. 이 기능은 Kerberos를 사용할 수 있는지 여부에 관계없이 모든 로컬 연결에서 NTLM을 사용하도록 강제합니다.

SQL Server Management Studio 사용

  1. SQL Server Management Studio를 열고 SQL Server 인스턴스에 연결합니다.

  2. 다음 쿼리를 실행합니다.

    SELECT auth_scheme FROM sys.dm_exec_connections WHERE session_id = @@SPID
    
  3. 또는 추가 연결 세부 정보를 검색하려면 다음 쿼리를 실행합니다.

    SELECT c.session_id, c.net_transport, c.encrypt_option,
           c.auth_scheme, s.host_name, @@SERVERNAME AS "remote_name",
           s.program_name, s.client_interface_name, s.login_name,
           s.nt_domain, s.nt_user_name, s.original_login_name,
           c.connect_time, s.login_time
    FROM sys.dm_exec_connections AS c
    JOIN sys.dm_exec_sessions AS s ON c.session_id = s.session_id
    WHERE c.session_id = @@SPID
    
  4. 결과의 auth_scheme 열을 검토하여 인증 유형을 확인합니다.

명령줄 사용

  1. 명령 프롬프트를 여세요.

  2. 서버 이름으로 <ServerName>를 바꾸고 다음 명령을 실행합니다.

    sqlcmd -S <ServerName> -E -Q "SELECT auth_scheme FROM sys.dm_exec_connections WHERE session_id = @@SPID"
    
  3. 다음 출력과 유사한 결과는 인증 유형을 나타냅니다.

    auth_scheme
    ----------------------------------------
    NTLM
    
    (1 rows affected)
    

VBScript 사용

  1. 다음 VBScript 코드를 메모장과 같은 텍스트 편집기에 복사하고 getAuthScheme.vbs로 저장합니다.

    ' Auth scheme VB script.
    ' Run on a client machine, not the server.
    ' If you run locally, you will always get NTLM even if Kerberos is properly enabled.
    '
    ' USAGE:  CSCRIPT getAuthScheme.vbs tcp:SQLProd01.contoso.com,1433   ' explicitly specify DNS suffix, protocol, and port # ('tcp' must be lower case)
    ' USAGE:  CSCRIPT getAuthScheme.vbs SQLProd01                        ' let the driver figure out the DNS suffix, protocol, and port #
    '
    Dim cn, rs, s
    s = WScript.Arguments.Item(0)              ' get the server name from the command-line
    Set cn = createobject("adodb.connection")
    '
    ' Various connection strings depending on the driver/Provider installed on your machine
    ' SQLOLEDB is selected as it is on all windows machines, but may have limitations, such as lack of TLS 1.2 support
    ' Choose a newer provider or driver if you have it installed.
    '
    cn.open "Provider=SQLOLEDB;Data Source=" & s & ";Initial Catalog=master;Integrated Security=SSPI"          ' On all Windows machines
    'cn.open "Provider=SQLNCLI11;Data Source=" & s & ";Initial Catalog=master;Integrated Security=SSPI"        ' Newer
    'cn.open "Provider=MSOLEDBSQL;Data Source=" & s & ";Initial Catalog=master;Integrated Security=SSPI"       ' Latest, good for SQL 2012 and newer
    'cn.open "Driver={ODBC Driver 17 for SQL Server};Server=" & s & ";Database=master;Trusted_Connection=Yes"  ' Latest
    '
    ' Run the query and display the results
    '
    set rs = cn.Execute("SELECT auth_scheme FROM sys.dm_exec_connections WHERE session_id = @@SPID")
    WScript.Echo "Auth scheme: " & rs(0)
    rs.close
    cn.close
    
  2. 명령 프롬프트에서 다음 명령어를 실행하고 <ServerName>을(를) 서버 이름으로 바꿔서 사용하세요.

    cscript getAuthScheme.vbs <ServerName>
    
  3. 다음 출력과 유사한 결과는 인증 유형을 나타냅니다.

    Microsoft (R) Windows Script Host Version 5.812
    Copyright (C) Microsoft Corporation. All rights reserved.
    Auth scheme: NTLM
    

Windows PowerShell 사용

Windows PowerShell을 사용하여 SqlClient .NET 공급자를 테스트하여 애플리케이션에서 문제를 격리할 수 있습니다.

  1. 다음 PowerShell 스크립트를 메모장과 같은 텍스트 편집기에 복사하고 get-SqlAuthScheme.ps1저장합니다.

    #-------------------------------
    #
    # get-SqlAuthScheme.ps1
    #
    # PowerShell script to test a System.Data.SqlClient database connection
    #
    # USAGE: 
    #   .\get-SqlAuthScheme tcp:SQLProd01.contoso.com,1433   # Explicitly specify DNS suffix, protocol, and port ('tcp' must be lowercase)
    #   .\get-SqlAuthScheme SQLProd01                        # Let the driver figure out the DNS suffix, protocol, and port
    #
    #-------------------------------
    # Define a parameter for the server name, defaulting to "localhost" if not provided
    param ([string]$server = "localhost")
    
    # Set the execution policy for the current user to Unrestricted
    Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    
    # Build the connection string for the SQL Server connection
    $connstr = "Server=$($server);Database=master;Integrated Security=SSPI"
    
    # Create a new SQL connection object
    $conn = New-Object System.Data.SqlClient.SqlConnection
    $conn.ConnectionString = $connstr
    
    # Record the start time of the operation
    $start = Get-Date
    
    # Open the SQL connection
    $conn.Open()
    
    # Create a new SQL command object
    $cmd = $conn.CreateCommand()
    $cmd.CommandText = "SELECT auth_scheme FROM sys.dm_exec_connections WHERE session_id = @@SPID" # Query to get the authentication scheme
    
    # Execute the query and retrieve the result
    $dr = $cmd.ExecuteReader()
    $dr.Read() | Out-Null # Read the first row of the result set
    $auth_scheme = $dr.GetString(0) # Get the authentication scheme from the first column
    
    # Close and dispose of the SQL connection
    $conn.Close()
    $conn.Dispose()
    
    # Record the end time of the operation
    $end = Get-Date
    
    # Calculate the elapsed time
    $span = $end - $start
    
    # Output the results
    Write-Output "Elapsed time was $($span.TotalMilliseconds) ms."    # Display the elapsed time in milliseconds
    Write-Output "Auth scheme for $($server): $auth_scheme"   # Display the authentication scheme for the server
    
  2. Windows PowerShell을 열고 스크립트가 포함된 폴더로 이동하고 다음 명령을 실행합니다.

    .\get-sqlauthscheme <ServerName>  # Replace "<ServerName>" with your server name.
    
  3. 다음 출력과 유사한 결과는 인증 유형을 나타냅니다.

    Elapsed time was 0 ms.
    Auth scheme for <ServerName>: NTLM
    

자세한 정보