adutil 簡介 - Active Directory 公用程式

適用於:SQL Server - Linux

adutil 工具是一項命令列介面 (CLI) 公用程式,可為 Linux 上的 SQL Server 和容器設定和管理 Windows Active Directory 網域,而不需要在 Windows 和 Linux 電腦之間切換來管理 Active Directory。

只有 SQL Server 使用案例才支援 adutil

您不需要使用 adutil 為 Linux 上的 SQL Server 或容器啟用 Active Directory 驗證。 您也可以使用 ktpass 之類的公用程式,如教學課程:透過 Linux 上的 SQL Server 使用 Active Directory 驗證中所述。

adutil 工具設計成一系列命令和子命令,其中包含您指定為進一步輸入的額外旗標。 每個最上層命令都代表系統管理功能的一個類別。 在該類別中,每個子命令都是一項作業。 本文說明如何下載並開始使用 adutil

為透過安全通訊端層 (SSL) 進行的 LDAP 設定 adutil

您應該使用透過 SSL 進行的輕量型目錄存取通訊協定 (LDAPS),而不是輕量型目錄存取通訊協定 (LDAP)。 如果您想要深入了解 LDAP,請參閱輕量型目錄存取通訊協定 (LDAP)

您可以在 adutil.json 組態檔中,將 useLdaps 選項設定為 true (當您以 mssql 使用者執行時,該檔案會位於 /var/opt/mssql/.adutil/adutil.json 中)。 此 JSON 程式碼範例示範如何進行設定:

{
    "useLdaps": "true"
}

根據預設,useLDAPS 設定會設定為 false。 設定此設定並使用 mssql-conf 建立金鑰表時,請確定您以使用者 mssql 身分執行 mssql-conf,您可以透過執行下列命令來完成:

sudo su mssql

若要使用 mssql-conf 設定金鑰表,請參閱使用 mssql-conf 建立 SQL Server 服務金鑰表檔案

安裝 adutil

如果您在安裝期間未接受 EULA,當您第一次執行 adutil 命令時,您必須使用 --accept-eula 旗標 (適用於所有發行版本) 來執行。

  1. 下載 Microsoft Red Hat 存放庫組態檔。

    sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/8/prod.repo
    
  2. 如果已安裝舊版 adutil,請使用下列命令移除任何舊版 adutil 套件。

    sudo yum remove adutil-preview
    
  3. 執行下列命令以安裝 adutilACCEPT_EULA=Y 會接受 adutil 的 EULA。 EULA 則位於路徑 /usr/share/adutil/

    sudo ACCEPT_EULA=Y yum install -y adutil
    

使用 adutil 管理 Windows Active Directory

請確定您將 adutil 下載至已加入 Active Directory 網域的主機。 您也需要使用 kinit 命令和特殊權限網域帳戶,取得或更新 Kerberos TGT (票證授權票證)。 您使用的帳戶必須具有在網域上建立帳戶和服務主體名稱 (SPN) 的權限。

以下是您可以使用 adutil 執行的一些動作範例。 若要查看最上層命令清單,請鍵入 adutil --help。 此命令會顯示可用來管理 Active Directory 並與其互動的最上層命令。

$ adutil --help
adutil - A general AD utility
  Usage:
    adutil [account|delegation|group|keytab|machine|ou|spn|user|config]
  Subcommands:
    account      Functions for generic account operations
    delegation   Functions for configuring delegation permissions
    group        Functions for group management
    keytab       Functions for keytab management
    machine      Functions for managing machine accounts
    ou           Functions for managing organizational units
    spn          Functions for service principal name (SPN) management
    user         Functions for user account management
    config       Functions for modifying adutil configuration
  Flags:
       --version       Displays the program version string.
    -h --help          Displays help with available flag, subcommand, and positional value parameters.
    -d --debug         Display additional debugging information when making LDAP/Kerberos calls.
       --accept-eula   Accepts the current EULA for adutil. This has no effect if the EULA has already been accepted.

如需下一層命令的說明,您可以執行下列 help 選項:

$ adutil spn --help
spn - Functions for service principal name (SPN) management
  Usage:
    spn [add|addauto|delete|search|show]
  Subcommands:
    add       Adds the provided SPNs to an account
    addauto   Automatically generate SPNs based on SPN component inputs and add them to an account
    delete    Deletes the provided SPNs from an account
    search    Search for an SPN by name or list all SPNs in the directory
    show      Get the list of SPNs assigned to an account
  Flags:
    --version       Displays the program version string.
    -h --help          Displays help with available flag, subcommand, and positional value parameters.
    -d --debug         Display additional debugging information when making LDAP/Kerberos calls.
       --accept-eula   Accepts the current EULA for adutil. This has no effect if the EULA has already been accepted.
$ adutil spn search --help
search - Search for an SPN by name or list all SPNs in the directory
  Usage:
     search [name]
  Positional Variables:
    name   OPTIONAL: Name of the SPN to search for in the directory. * can be used as a wildcard
  Flags:
    --version       Displays the program version string.
    -h --help          Displays help with available flag, subcommand, and positional value parameters.
    -n --name          OPTIONAL: Name of the SPN to search for in the directory. * can be used as a wildcard
    -f --filter        OPTIONAL: Filter for the search (User,Machine,Group)
    -o --ouname        OPTIONAL: Distinguished name of OU in which SPNs should be searched. If omitted, the entire directory will be searched.
    -d --debug         Display additional debugging information when making LDAP/Kerberos calls.
       --accept-eula   Accepts the current EULA for adutil. This has no effect if the EULA has already been accepted.

範例

每個命令都有說明,因此您可以立即開始使用。 以下是為 Linux 上的 SQL Server 和容器設定或管理 Active Directory 驗證時,使用 adutil 的一些典型活動:

  • 在 Active Directory 中建立帳戶:

    adutil user create --name sqluser --distname CN=sqluser,CN=Users,DC=CONTOSO,DC=COM
    
  • 建立與帳戶或服務相關聯的 SPN:

    adutil spn addauto -n sqluser -s MSSQLSvc -H mymachine.contoso.com -p 1433
    
  • 使用 adutil 建立金鑰表:

    adutil keytab createauto -k /var/opt/mssql/secrets/mssql.keytab -p 1433 -H mymachine.contoso.com --password 'P@ssw0rd' -s MSSQLSvc
    

您可以使用命令 man adutil 來參考 adutil 的參考手冊頁面。