發新話題
打印

使用 Samba 架設 File Server,整合 AD 2003 帳號

使用 Samba 架設 File Server,整合 AD 2003 帳號

http://blog.yam.com/gavint/article/4530697

之前在恆逸上課,老師曾教過使用 Samba 架設 File Server,並與 AD 2003 整合,正好手邊有一台勘用,但公司要報廢的電腦,於是拿來測試。


 測試環境:
  AD Server:twadc.sample.com
  AD Server IP:10.1.1.57
  WINS Server IP:10.1.1.57
  DNS Server IP:10.1.1.57
  Linux:Fedora 5
  套件:samba-3.0.23c-1.fc5

一、整合 AD 2003 帳號
 1. 設定 Samba
  # vi /etc/samba/smb.conf
  [global]
  workgroup = sample <- 網域名稱
  realm = sample.com <- 完整網域名稱
  netbios name = linux-src <- 主機名稱
  server string = Linux Src Server <- 電腦描述
  display charset = Big5 <- 支援中文 ShareName
  dos charset = CP950
  unix charset = Big5
  security = ads <- AD 網域認證模式
  password server = twadc.sample.com <- 密碼主機
  encrypt passwords = yes <- 密碼加密
  wins server = 10.1.1.57 <- WINS 主機
  idmap uid = 16777000-33550000  <- 修改 GID 與 UID 的範圍及目錄
  idmap gid = 16777000-33550000  <- (Linux 從 AD 讀取的帳號)
  winbind enum users = yes
  winbind enum groups = yes
  template shell = /bin/bash <- 指定 AD 帳號的 Shell
  winbind use default domain = yes <- 是否自動套用網域名稱
  template homedir = /home/%D/%U <- %D 網域名稱,%U 帳號

 2. 設定 DNS 或 hots
  # vi /etc/resolv.conf
  nameserver 10.1.1.57
  或
  # vi /etc/hosts
  10.1.1.57 twadc.sample.com sample.com
  只要修改其中一種能查詢到 sample.com 網域即可。

 3. 修改 Kerberos
  # vi /etc/krb5.conf
  [libdefaults]
  default_realm = twadc.sample.com <- AD 主機

  [realms]
  SAMPLE.COM = { <- 改成網域
   KDC = twadc.sample.com:88 <- AD 認證主機
   admin_server = twadc.sample.com:749 <- AD 認證主機
   default_domain = sample.com <- 完整網域名稱
  }

  [domain_realm]
  .example.com = SAMPLE.COM <- 完整網域名稱
  example.com = SAMPLE.COM <- 完整網域名稱

  # vi /var/kerberos/krb5kdc/kdc.conf <- 如果沒有此檔案,則代表未安裝krb5-server
  [realms]
  SAMPLE.COM = { <- 完整網域名稱
  ................................
  }

 4. 重新啟動 samba 及 winbind
  # service smb restart
  # service winbind restart

  設定開機啟動
  # chkconfig smb on
  # chkconfig winbind on


 5. 加入 sample.com 網域
  # net ads join -U joindomain <- joindomain 為網域帳號
  joindomain's password:

 6. 設定與 DC 溝通時的使用者
  # wbinfo --set-auth-user=user(具一般使用者權限即可)
  Password:

 7. 編輯 NSS 設定檔
  # vi /etc/nsswitch.conf <- 設定認證順序
  passwd: files winbind
  shadow: files
  group: files winbind

 8. 測試連線
  # kinit administrator@SAMPLE.COM <- 網域名稱要大寫
  若密碼正確會跳回命令提示字元
  AD主機與Linux主機兩台時間不得相差超過5分鐘 <- 這個部份很容易忽略,要注意。


 9. 測試讀取 AD 帳號資訊
  # wbinfo -u
  或
  # getent passwd

 10. 設定本機 UID 與 GID 發放範圍,避免 AD 帳號與 Linux 本機帳號衝突
  # vi /etc/login.defs
  UID_MIN 500
  UID_MAX 9999 <- 改為9999

  GID_MIN 500
  GID_MAX 9999 <- 改為9999

二、整合 Samba
  # vi /etc/pam.d/samba
  #%PAM-1.0
  auth       required     pam_nologin.so
  auth       sufficient   /lib/security/pam_winbind.so <- 加入這行
  auth       required     pam_stack.so service=system-auth
  account    sufficient   /lib/security/pam_winbind.so <- 加入這行
  account    required     pam_stack.so service=system-auth
  session    required     pam_stack.so service=system-auth
  password   required     pam_stack.so service=system-auth

三、分享目錄
  # vi /etc/samba/smb.conf
  [SRC]
   comment = Linux Src <- 目錄描述
   path = /ftpdata <- 分享路徑
   valid users = sample\gavin sample\ida <- 允許的使用者,格式為 網域\帳號 
   public = yes <- 是否公開
   writable = yes <- 是否可寫入

  # service smb restart

四、開啟 ACL
  # vi /etc/fstab
  /dev/hdaX /ftpdata ext3 defaults,acl 1 2

  # mount -ro,remount /dev/hdaX <- 重新掛載
 
 開啟 ACL 可讓 File Server 支援 MS 的 User Security

五、設定安全性
  1. 在分享的目錄下新增子目錄,並按滑鼠右鍵,選擇「內容」
  2. 點選「安全性」,即可看到與 Windows 下同樣的安全性設定。

  註:雖可使用 Windows 下的安全性圖形介面,設定權限,但並非百分之百完全支援。

六、啟動網路資源回收筒機制
  # vi /etc/samba/smb.conf
  [SRC]
   comment = Linux Src
   path = /ftpdata
   valid users = sample\gavin sample\ida
   public = yes
   writable = yes

   在分享目錄後,增加下面幾行
   vfs object = recycle
   recycle:keeptree = yes
   recycle:versions = yes
   recycle:repository = ../Garbage/%u

   『recycle:keeptree = yes』:刪除的資料,到了網路資源回收筒後,仍然保有其樹狀結構。
   『recycle:versions = yes』:保留相同的檔案名稱。
   『recycle:repository = ../Garbage/%u』:資源回收筒存放位置,需使用相對路徑表示。

   Garbage資料夾的權限需注意,必須讓使用者具有『rwx』權限,且共享的目錄必須設定 sticky 權限,避免資料被非擁有者刪除。
   還原時可使用 cp -p 的指令還原到原先的資料夾中。

TOP

發新話題