Try   HackMD

建立Windows網域共享

以下是以 ubuntu 環境建置,其他發行版本應該也差不多。

基本必要軟體安裝

​​  apt -y install samba libpam-winbind libnss-winbind
​​  apt -y install \
​​   winbind libpam-winbind \
​​   libnss-winbind krb5-config samba-dsdb-modules\
​​   samba-vfs-modules samba acl

修正 /etc/krb5.conf 只放下列項目就好,其他預設的都清掉

​​[libdefaults]
​​   default_realm = ERILAB.COM.TW
​   dns_lookup_realm = false
​   dns_lookup_kdc = true

編輯 /etc/nsswitch.conf

​​...略
​​passwd:     compat systemd winbind
​​group:     compat systemd winbind
​​...略

smb.conf 設定

刪除或改名原本的 smb.conf , 新增 /etc/samba/smb.conf 內容大致如下

​​[global]
​​    #bind interfaces only = yes
​​    #interfaces = lo eth0
​​    workgroup = ERILAB
​​    realm = ERILAB.COM.TW
​​
​​    # 實際註冊進網域時用的名稱,沒設定的話會直接用HostName
​​    # netbios name = XXXFileServer
​​
​​    security = ads
​​    idmap config * : backend = tdb
​​    idmap config * : range = 3000-7999
​​    idmap config ERI : backend = rid
​​    idmap config ERI : range = 10000-999999
​​    template homedir = /home/%U
​​    template shell = /bin/bash
​​    winbind use default domain = true
​​    winbind offline logon = false
​​
​​    min protocol = SMB3_11
​​
​​#分享設定 , 是需要可以在往下加.
​​[DockerVol]
​​    path = /DockerVol
​​    admin users = @sudo
​​    #valid users = @"domain admins"
​​    browsable = yes
​​    writable = yes
​​    read only = no

進行網域加入

​​net ads join -U Administrator
​​systemctl restart smbd.service winbind.service

​​net ads join osname=`uname -s` osver=`uname -r` -U admin...
​​# 完成上面動作後可以用下面指令取得網域帳號列表.  
​​(如果加入有成功的話應該可以看到清清單)
​​wbinfo -u
​​wbinfo -g

補充說明:

  • 加入網域後預設所有網域成員都可以 ssh 連進主機 , 可調整 /etc/ssh/sshd_config 進行限制
    ​​​​...略
    ​​​​# 只允許本機 adm , sudo 群組 , ssh 遠端登入
    ​​​​AllowGroups adm sudo
    ​​​​...略
    
  • 將網域帳號 peter 加入本機 sudo 群組
    ​​​​usermod -G sudo peter
    
  • 查看目前 sudo 群組中有哪些成員
    ​​​​groupmems -l -g sudo
    
  • 調整 groupmems 執行權限問題.
    ​​​​cat << END > /etc/pam.d/groupmems
    ​​​​#%PAM-1.0
    ​​​​auth            sufficient      pam_rootok.so
    ​​​​account         required        pam_permit.so
    ​​​​password        include         system-auth(common-password)
    ​​​​END
    
  • 從 sudo 中移除特定使用者
    ​​​​gpasswd -d olduser -g sudo
    

網路參考資料