SAMBA with ActiveDirectory
SAMBAをActiveDirectory(以下、AD)と連携させる機会があったので備忘録
いろんな事
- 昔のWindows2003時代はADとの連携にService For Unix(以下、SFU)を利用していたことが多い
- Windows2003R2からはSubsystem for Unix Application(以下、SUA)を利用していたことが多い
- Windows2012からはSUAが非推奨となったので、別の方法で実現しなさいとMicrosoftさんは言っている
- SFUやSUAで何を連携していたかと言うとNISサーバー経由でのUID/GID。
- idmapを使ってUID/GIDを変換している
- idmapはwinbindが担っている
- winbindのidmappingはtdbデータベースで管理されており、キャッシュされている
- 一度キャッシュされたデータはなかなか消えない??
- キャッシュディレクトリは/var/lib/samba
- SAMBA本体も含め全ファイル削除するには、ディレクトリを削除すればOK。ディレクトリは次の起動時に自動生成されるが、samba/privateとsamba/scriptsだけは自動生成されないので、手動で作成しておく必要あり。作成し忘れるとSAMBAがエラーになる
設定の確認
設定が完了したら色々な方法で確認できる
kinit administrator@AD.LOCAL kerberos認証を実行してキャッシュする
klist kerberos認証している情報を表示
wbinfo -u ユーザー一覧の表示
wbinfo -g グループ一覧の表示
wbinfo -n <username> usernameのSIDを表示
id <domain user name> ユーザ情報の表示、ローカルLinuxユーザもドメインユーザも表示できる
実際の設定
| ADドメイン名 | ad.local. |
|---|---|
| NTドメイン名 | AD |
| ADのDC名 | win.ad.local. |
| SAMBAサーバー名 | samba.ad.local. |
| SAMBAサーバーNETBIOS名 | SAMBA |
idmap周りの設定ではまります
設定していて思う通りに行かないときは、sambaのloglevelを10に上げておいて
logディレクトリのlog.winbindとlog.winbind-idmapを確認するのが良い
base_ridを500としているのはAD側のビルトインユーザUIDやグループGIDが500番から始まっていて
ridモジュールのidmappingでrangeエラーになっていたのを対応するため
samba関連をインストール samba samba-winbind krb5-workstation
kerberos設定 /etc/krb5.conf
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
[libdefaults]
default_realm = AD.LOCAL
[realms]
AD.LOCAL = {
kdc = win.ad.local
admin_server = win.ad.local
}
[domain_realm]
.ad.local = AD.LOCAL
ad.local = AD.LOCAL
/etc/samba/smb.conf
smb.conf
[global]
unix charset = UTF8
display charset = UTF8
dos charset = cp932
log file = /var/log/samba/log.%m
log level = 3
syslog = 0
workgroup = AD
server string = AD file server
security = ads
realm = AD.LOCAL
netbios name = samba
winbind separator = +
winbind use default domain = yes
encrypt passwords = yes
idmap config * : backend = tdb
idmap config * : range = 500-20000
idmap config AD : backend = rid
idmap config AD : range = 10000 - 20000
idmap config AD : base_rid = 500
[share]
path = /samba/share
store dos attributes = yes
nt acl support = yes
writeable = yes
browseable = yes
comment = 読み書き自由
create mask = 0770
directory mask = 0770
inherit permissions = Yes
public = yes
guest ok = yes
guest only = yes
[ads-share]
path = /samba/ads-share
comment = ADユーザのみ共有
valid users = "@+domain users"
read only = no
writable = yes
browseable = yes
nt acl support = yes
store dos attributes = yes
inherit permissions = Yes
[ads-admin]
path = /samba/ads-admin
comment = AD特定ユーザのみ
valid users = 'username'
read only = no
writable = yes
browseable = yes
nt acl support = yes
store dos attributes = yes
inherit permissions = Yes
