本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 Winbind 手動將 Amazon EC2 Linux 執行個體加入 AWS Managed Microsoft AD Active Directory
您可以使用 Winbind 服務,將 Amazon EC2 Linux 執行個體手動加入 AWS Managed Microsoft AD Active Directory 網域。這可讓您現有的內部部署 Active Directory 使用者在存取加入 AWS Managed Microsoft AD Active Directory 的 Linux 執行個體時,使用其 Active Directory 登入資料。系統支援下列 Linux 執行個體分佈和版本:
-
Amazon Linux AMI 2018.03.0
-
Amazon Linux 2 (64 位元 x86)
-
Amazon Linux 2023 AMI
-
Red Hat Enterprise Linux 8 (HVM) (64 位元 x86)
-
Ubuntu Server 18.04 LTS 及 Ubuntu Server 16.04 LTS
-
CentOS 7 x86-64
-
SUSE Linux Enterprise Server 15 SP1
其他 Linux 分佈和版本也許能正常運作,但尚未經過測試。
將 Linux 執行個體加入您的 AWS Managed Microsoft AD Active Directory
以下某些程序若未正確執行,可能會導致您的執行個體無法連線或無法使用。因此,我們強烈建議您在執行這些程序之前,對您的執行個體進行備份或擷取快照。
將 Linux 執行個體加入您的目錄
使用以下其中一個標籤,依照您的特定 Linux 執行個體的步驟:
- Amazon Linux/CENTOS/REDHAT
-
-
使用任何 SSH 用戶端連線到執行個體。
-
設定 Linux 執行個體,讓其得以使用 AWS Directory Service所提供之 DNS 伺服器的 DNS 伺服器 IP 地址。欲執行此作業,您可以在連接到 VPC 的 DHCP 選項集中進行設定,或在執行個體上手動設定。如果您想要手動設定,請參閱 AWS 知識中心中的如何將靜態 DNS 伺服器指派給私有 Amazon EC2 執行個體,以取得為特定 Linux 發行版本設定持久性 DNS 伺服器的指引。
-
請確定您的 Linux 執行個體處於最新狀態。
sudo yum -y update
-
在您的 Linux 執行個體上安裝必要的 Samba / Winbind 套裝服務。
sudo yum -y install authconfig samba samba-client samba-winbind samba-winbind-clients
-
備份主 smb.conf
檔案,以便在發生任何故障時可以恢復:
sudo cp /etc/samba/smb.conf /etc/samba/smb.bk
-
在文字編輯器中開啟原始組態檔案 [/etc/samba/smb.conf
] 。
sudo vim /etc/samba/smb.conf
填寫您的 Active Directory 網域環境資訊,如下列範例所示:
[global]
workgroup = example
security = ads
realm = example.com
idmap config * : rangesize = 1000000
idmap config * : range = 1000000-19999999
idmap config * : backend = autorid
winbind enum users = no
winbind enum groups = no
template homedir = /home/%U@%D
template shell = /bin/bash
winbind use default domain = false
-
在文字編輯器中開啟 [/etc/hosts
] 檔案。
sudo vim /etc/hosts
新增 Linux 執行個體私有 IP 地址,如下所示:
10.x.x.x
Linux_hostname
.example.com
Linux_hostname
如果您未在 /etc/hosts
檔案中指定 IP 地址,則在將執行個體加入域時可能會收到下列 DNS 錯誤:
No DNS domain configured for linux-instance. Unable to perform DNS
Update. DNS update failed: NT_STATUS_INVALID_PARAMETER
此錯誤表示加入成功,但 [net ads] 命令無法在 DNS 中登錄 DNS 記錄。
-
使用 net 公用程式將 Linux 執行個體加入 Active Directory。
sudo net ads join -U join_account@example.com
Enter join_account@example.com
's password:
Using short domain name -- example
Joined 'IP-10-x-x-x
' to dns domain 'example.com
'
-
修改 PAM 組態檔案,使用以下命令新增 winbind 身分驗證所需的項目:
sudo authconfig --enablewinbind --enablewinbindauth --enablemkhomedir --update
-
透過編輯 /etc/ssh/sshd_config
檔案,設定 SSH 服務以允許密碼身分驗證。
-
在文字編輯器中開啟 /etc/ssh/sshd_config
檔案。
sudo vi /etc/ssh/sshd_config
-
將 PasswordAuthentication
設定設為 yes
。
PasswordAuthentication yes
-
重新啟動 SSH 服務。
sudo systemctl restart sshd.service
或使用:
sudo service sshd restart
-
重新啟動執行個體之後,請執行下列步驟,以使用任何 SSH 用戶端連線到該執行個體,並將域使用者或群組的根權限新增至 sudoers 清單:
-
使用下列命令開啟 sudoers
檔案:
sudo visudo
-
從信任或受信任域中新增所需群組或使用者,如下所示,然後儲存。
## Adding Domain Users/Groups.
%domainname
\\AWS\ Delegated\ Administrators ALL=(ALL:ALL) ALL
%domainname
\\groupname
ALL=(ALL:ALL) ALL
domainname
\\username
ALL=(ALL:ALL) ALL
%Trusted_DomainName
\\groupname
ALL=(ALL:ALL) ALL
Trusted_DomainName
\\username
ALL=(ALL:ALL) ALL
(上述範例使用 "\<space>" 來建立 Linux 空白字元。)
- SUSE
-
-
使用任何 SSH 用戶端連線到執行個體。
-
設定 Linux 執行個體,讓其得以使用 AWS Directory Service所提供之 DNS 伺服器的 DNS 伺服器 IP 地址。欲執行此作業,您可以在連接到 VPC 的 DHCP 選項集中進行設定,或在執行個體上手動設定。如果您想要手動設定,請參閱 AWS 知識中心中的如何將靜態 DNS 伺服器指派給私有 Amazon EC2 執行個體,以取得為特定 Linux 發行版本設定持久性 DNS 伺服器的指引。
-
請確定您的 SUSE Linux 15 執行個體處於最新狀態。
-
連接套件儲存庫。
sudo SUSEConnect -p PackageHub/15.1/x86_64
-
更新 SUSE。
sudo zypper update -y
-
在您的 Linux 執行個體上安裝必要的 Samba / Winbind 套裝服務。
sudo zypper in -y samba samba-winbind
-
備份主 smb.conf
檔案,以便在發生任何故障時可以恢復:
sudo cp /etc/samba/smb.conf /etc/samba/smb.bk
-
在文字編輯器中開啟原始組態檔案 [/etc/samba/smb.conf
] 。
sudo vim /etc/samba/smb.conf
填寫 Active Directory 域環境訊息,如下例所示:
[global]
workgroup = example
security = ads
realm = example.com
idmap config * : rangesize = 1000000
idmap config * : range = 1000000-19999999
idmap config * : backend = autorid
winbind enum users = no
winbind enum groups = no
template homedir = /home/%U@%D
template shell = /bin/bash
winbind use default domain = false
-
在文字編輯器中開啟 [/etc/hosts
] 檔案。
sudo vim /etc/hosts
新增 Linux 執行個體私有 IP 地址,如下所示:
10.x.x.x
Linux_hostname
.example.com
Linux_hostname
如果您未在 /etc/hosts
檔案中指定 IP 地址,則在將執行個體加入域時可能會收到下列 DNS 錯誤:
No DNS domain configured for linux-instance. Unable to perform DNS
Update. DNS update failed: NT_STATUS_INVALID_PARAMETER
此錯誤表示加入成功,但 [net ads] 命令無法在 DNS 中登錄 DNS 記錄。
-
使用下列命令將 Linux 執行個體加入目錄。
sudo net ads join -U join_account@example.com
Enter join_account@example.com
's password:
Using short domain name -- example
Joined 'IP-10-x-x-x
' to dns domain 'example.com
'
-
修改 PAM 組態檔案,使用以下命令新增 Winbind 身分驗證所需的項目:
sudo pam-config --add --winbind --mkhomedir
-
在文字編輯器中開啟名稱服務交換器組態檔案 [/etc/nsswitch.conf
]。
vim /etc/nsswitch.conf
新增 Winbind 指令,如下所示。
passwd: files winbind
shadow: files winbind
group: files winbind
-
透過編輯 /etc/ssh/sshd_config
檔案,設定 SSH 服務以允許密碼身分驗證。
-
在文字編輯器中開啟 /etc/ssh/sshd_config
檔案。
sudo vim /etc/ssh/sshd_config
-
將 PasswordAuthentication
設定設為 yes
。
PasswordAuthentication yes
-
重新啟動 SSH 服務。
sudo systemctl restart sshd.service
或使用:
sudo service sshd restart
-
重新啟動執行個體之後,請執行下列步驟,以使用任何 SSH 用戶端連線到該執行個體,並將域使用者或群組的根權限新增至 sudoers 清單:
-
使用下列命令開啟 sudoers
檔案:
sudo visudo
-
從信任或受信任域中新增所需群組或使用者,如下所示,然後儲存。
## Adding Domain Users/Groups.
%domainname
\\AWS\ Delegated\ Administrators ALL=(ALL:ALL) ALL
%domainname
\\groupname
ALL=(ALL:ALL) ALL
domainname
\\username
ALL=(ALL:ALL) ALL
%Trusted_DomainName
\\groupname
ALL=(ALL:ALL) ALL
Trusted_DomainName
\\username
ALL=(ALL:ALL) ALL
(上述範例使用 "\<space>" 來建立 Linux 空白字元。)
- Ubuntu
-
-
使用任何 SSH 用戶端連線到執行個體。
-
設定 Linux 執行個體,讓其得以使用 AWS Directory Service所提供之 DNS 伺服器的 DNS 伺服器 IP 地址。欲執行此作業,您可以在連接到 VPC 的 DHCP 選項集中進行設定,或在執行個體上手動設定。如果您想要手動設定,請參閱 AWS 知識中心中的如何將靜態 DNS 伺服器指派給私有 Amazon EC2 執行個體,以取得為特定 Linux 發行版本設定持久性 DNS 伺服器的指引。
-
請確定您的 Linux 執行個體處於最新狀態。
sudo apt-get -y upgrade
-
在您的 Linux 執行個體上安裝必要的 Samba / Winbind 套裝服務。
sudo apt -y install samba winbind libnss-winbind libpam-winbind
-
備份主 smb.conf
檔案,以便在發生任何故障時可以恢復。
sudo cp /etc/samba/smb.conf /etc/samba/smb.bk
-
在文字編輯器中開啟原始組態檔案 [/etc/samba/smb.conf
] 。
sudo vim /etc/samba/smb.conf
填寫 Active Directory 域環境訊息,如下例所示:
[global]
workgroup = example
security = ads
realm = example.com
idmap config * : rangesize = 1000000
idmap config * : range = 1000000-19999999
idmap config * : backend = autorid
winbind enum users = no
winbind enum groups = no
template homedir = /home/%U@%D
template shell = /bin/bash
winbind use default domain = false
-
在文字編輯器中開啟 [/etc/hosts
] 檔案。
sudo vim /etc/hosts
新增 Linux 執行個體私有 IP 地址,如下所示:
10.x.x.x
Linux_hostname
.example.com
Linux_hostname
如果您未在 /etc/hosts
檔案中指定 IP 地址,則在將執行個體加入域時可能會收到下列 DNS 錯誤:
No DNS domain configured for linux-instance. Unable to perform DNS
Update. DNS update failed: NT_STATUS_INVALID_PARAMETER
此錯誤表示加入成功,但 [net ads] 命令無法在 DNS 中登錄 DNS 記錄。
-
使用 net 公用程式將 Linux 執行個體加入 Active Directory。
sudo net ads join -U join_account@example.com
Enter join_account@example.com
's password:
Using short domain name -- example
Joined 'IP-10-x-x-x
' to dns domain 'example.com
'
-
修改 PAM 組態檔案,使用以下命令新增 Winbind 身分驗證所需的項目:
sudo pam-auth-update --add --winbind --enable mkhomedir
-
在文字編輯器中開啟名稱服務交換器組態檔案 [/etc/nsswitch.conf
]。
vim /etc/nsswitch.conf
新增 Winbind 指令,如下所示。
passwd: compat winbind
group: compat winbind
shadow: compat winbind
-
透過編輯 /etc/ssh/sshd_config
檔案,設定 SSH 服務以允許密碼身分驗證。
-
在文字編輯器中開啟 /etc/ssh/sshd_config
檔案。
sudo vim /etc/ssh/sshd_config
-
將 PasswordAuthentication
設定設為 yes
。
PasswordAuthentication yes
-
重新啟動 SSH 服務。
sudo systemctl restart sshd.service
或使用:
sudo service sshd restart
-
重新啟動執行個體之後,請執行下列步驟,以使用任何 SSH 用戶端連線到該執行個體,並將域使用者或群組的根權限新增至 sudoers 清單:
-
使用下列命令開啟 sudoers
檔案:
sudo visudo
-
從信任或受信任域中新增所需群組或使用者,如下所示,然後儲存。
## Adding Domain Users/Groups.
%domainname
\\AWS\ Delegated\ Administrators ALL=(ALL:ALL) ALL
%domainname
\\groupname
ALL=(ALL:ALL) ALL
domainname
\\username
ALL=(ALL:ALL) ALL
%Trusted_DomainName
\\groupname
ALL=(ALL:ALL) ALL
Trusted_DomainName
\\username
ALL=(ALL:ALL) ALL
(上述範例使用 "\<space>" 來建立 Linux 空白字元。)
連線至 Linux 執行個體
當使用者使用 SSH 用戶端連線到執行個體時,系統會提示其輸入使用者名稱。如果使用者想輸入使用者名稱,可以善用 username@example.com
或 EXAMPLE\username
格式。視您使用的 Linux 發行版本而定,回應看起來會與下列類似:
Amazon Linux、Red Hat Enterprise Linux 及 CentOS Linux
login as: johndoe@example.com
johndoe@example.com's password:
Last login: Thu Jun 25 16:26:28 2015 from XX.XX.XX.XX
SUSE Linux
SUSE Linux Enterprise Server 15 SP1 x86_64 (64-bit)
As "root" (sudo or sudo -i) use the:
- zypper command for package management
- yast command for configuration management
Management and Config: https://www.suse.com/suse-in-the-cloud-basics
Documentation: https://www.suse.com/documentation/sles-15/
Forum: https://forums.suse.com/forumdisplay.php?93-SUSE-Public-Cloud
Have a lot of fun...
Ubuntu Linux
login as: admin@example.com
admin@example.com@10.24.34.0's password:
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-1057-aws x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sat Apr 18 22:03:35 UTC 2020
System load: 0.01 Processes: 102
Usage of /: 18.6% of 7.69GB Users logged in: 2
Memory usage: 16% IP address for eth0: 10.24.34.1
Swap usage: 0%