歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> FreeBSD配置samba

FreeBSD配置samba

日期:2017/2/28 11:16:17   编辑:關於Unix


配置samba
[global]設置
# This is the main Samba configuration file. You should read the
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# Any line which starts with a ; (semi-colon) or a # (hash)
# is a comment and is ignored. In this example we will use a #
# for commentry and a ; for parts of the config file that you
# may wish to enable
#
# NOTE: Whenever you modify this file you should run the command "testparm"
# to check that you have not many any basic syntactic errors.
#
#======================= Global Settings =====================================
[global]


  [global]部分定義了服務器本身使用的配置參數,以及其他共享資源部分使用的缺省配置參數,因此相當重要。
# workgroup = NT-Domain-Name or Workgroup-Name, eg: REDHAT4
workgroup = MYGROUP


  工作組設置本地網絡使用工作組名字(或者是NT域名字),這對於將正確進行浏覽數據中非常重要。否則,Windows客戶就不能從其網絡鄰居中發現這個Samba服務器。
# server string is the equivalent of the NT Description field
server string = Samba Server


  server string是對於本地服務器的簡單描述,這些信息將作為這台服務器的屬性,返回給Browser,顯示在Windows客戶中作為對這個服務器的描述。
# This option is important for security. It allows you to restrict
# connections to machines which are on your local network. The
# following example restricts access to two C class networks and
# the "loopback" interface. For more examples of the syntax see
; hosts allow = 192.168.1. 192.168.2. 127.


  hosts allow參數用於限制可以訪問這台samba服務器的客戶機的IP地址范圍,通過指定一系列網絡地址,使得只有這些網絡中的計算機才能訪問這台服務器提供的資源,以提供安全限制。缺省情況下,這行配置被注釋了,使得所有的客戶都可以訪問這台計算機,這樣就存在一定的安全問題。
# If you want to automatically load your printer list rather
# than setting them up individually then you'll need this
load printers = yes

# you may wish to override the location of the printcap file
; printcap name = /etc/printcap

# on SystemV system setting printcap name to lpstat should allow
# you to automatically obtain a printer list from the SystemV spool
# system
; printcap name = lpstat

# It should not be necessary to specify the print system type unless
# it is non-standard. Currently supported print systems include:
# bsd, sysv, plp, lprng, aix, hpux, qnx
; printing = bsd


  這些設置是用於設置samba服務器的打印機資源,load printer=yes就允許samba服務器對外共享服務器的打印機。由於不同的Unix系統中會使用不同的打印系統和不同的打印設置文件,因此需要設置正確的 printcap和printing類型,對於使用BSD打印系統的FreeBSD來講,打印系統為BSD,使用的設置文件為 printcap,這些是缺省設置,不需要改動。對於使用Unix System V打印系統的Samba,則需要重新進行設置。
# Uncomment this if you want a guest account, you must add this to /etc/passwd
# otherwise the user "nobody" is used
; guest account = pcguest


  由於Mircrosoft客戶沒有用戶的概念,因此有時會用沒有用戶和口令的請求訪問服務器,就需要將這個沒有用戶的請求映射為系統中的某個用戶,Samba服務器才能安全的訪問系統。guest account 就定義這樣的請求在Unix下對應的用戶權限。為了安全的原因,不能讓這個帳戶在系統中有可寫的權限,通常可以增加一個專用帳戶,如pcguest。如果這個設置被注釋的情況下,系統缺省使用nobody執行 Windows客戶的請求。一些使用者建議不要使用nobody用戶,因為系統中的很多程序缺省都使用它,因此就會有安全問題。
# this tells Samba to use a separate log file for each machine
# that connects
log file = /var/log/log.%m

# Put a capping on the size of the log files (in Kb).
max log size = 50


  這裡定義samba的日志文件為/var/log目錄下的以log為前綴的文件,%m用於代表從訪問的NetBIOS 計算機名,如果使用的用戶級認證,還可以使用%U表示不同的登錄用戶。例如從一台名字為win95c的計算機訪問samba服務器的日志,將記錄在/var/log/log.win95c文件中。max log size定義每個日志文件的存儲限制。
# Security mode. Most people will want user level security. See
# security_level.txt for details.
security = user
# Use password server option only with security = server
; password server =

# You may wish to use password encryption. Please read
# ENCRYPTION.txt, Win95.txt and WinNT.txt in the Samba documentation.
# Do not enable this option unless you have read those documents
; encrypt passwords = yes


  在SMB協議中,有多個不同的認證方式,包括簡單的共享級認證和用戶級認證。Unix為多用戶操作系統,缺省就使用用戶級認證方式。當使用用戶級認證的時候,Samba服務器使用Unix操作系統的用戶和口令(來自/etc/passwd )對用戶進行認證,這是一種獨立的認證方式。而有時候希望所有的服務器使用同一個認證數據庫進行統一認證,因此就導致出現了基於域的統一認證模式。在一個域中,用戶只需要通過域控制器進行認證即可,域中其他SMB服務器就將認可域控制器的認證。
  為了使Samba服務器支持域認證方式,可以有兩種不同的設置方式,一種為真正的域認證,另一種為服務器認證方式,將Samba服務器配置為通過服務器驗證用戶,這需要指定security=server,以及指定password server的名字為NT的域控制器。認證服務器的方式不能事先域認證方式提供的一些特征,但它的適用范圍並不僅限於域,使用工作組的網絡也能通過統一的認證服務器來使用統一認證模式。設置域認證方式在後面進行詳細解釋。
  在Windows NT 4及Windows 98之後,客戶和服務器之間進行認證時,口令不再以明文的方式在網絡中傳輸了。為了支持加密口令傳輸,需要設置encrypt passwords選項。同樣,這也需要其他復雜的設置。
# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting


# Most people will find that this option gives better performance.
# See speed.txt and the manual pages for details
socket options = TCP_NODELAY


  socket參數用於配置對TCP的處理方式,以適合Microsoft客戶的特征。Microsoft習慣為每個很短的會話都建立單獨的連接,而不是使用一個連接進行多次傳輸,這樣在傳輸中就需要進行多次連接會話設定過程,對性能有一定影響。為了改善性能,需要設置TCP_NODELAY或IPTOS_LOWDELAY選項。
# Configure Samba to use multiple interfaces
# If you have multiple network interfaces then you must list them
# here. See the man page for details.
; interfaces = 192.168.12.2/24 192.168.13.2/24


  如果計算機上有多個網絡界面,那麼就需要讓samba向多個界面廣播b-node廣播包,以及為這些界面提供資源服務,否則samba就會只向某一個界面提供網絡服務。當然也可以設置這個參數,使得samba 只服務於某個指定的網絡,而不是服務器連接所有的網絡。
# Browser Control Options:
# set local master to no if you don't want Samba to become a master
# browser on your network. Otherwise the normal election rules apply
; local master = no

# OS Level determines the precedence of this server in master browser
# elections. The default value should be reasonable
; os level = 33

# Domain Master specifies Samba to be the Domain Master Browser. This
# allows Samba to collate browse lists between subnets. Don't use this
# if you already have a Windows NT domain controller doing this job
; domain master = yes

# Preferred Master causes Samba to force a local browser election on startup
# and gives it a slightly higher chance of winning the election
; preferred master = yes
# Use only if you have an NT server on your network that has been
# configured at install time to be a primary domain controller.
; domain controller =


  這些設置選項主要用於SMB網絡中進行浏覽時,設置samba服務器的行為。缺省情況不讓samba服務器參加broswser的推舉過程,為了使得samba服務器能成為browser,就需要設定local master =yes。然後samba服務就可以根據os level設置的權重進行推舉,缺省的os level為0,這個權重不會贏得推舉。但可以取消注釋,將os level設置為33,這將在與所有Windows計算機(包括Windows NT)的推舉競賽中獲得勝利,因為NT server的權重為32。設置比33更高的權重,只是在不同的samba 服務器之間進行選擇時才有意義。
  由於Unix及Samba服務器在同樣硬件配置下具有更高的網絡性能,因此一般情況下,使用Samba服務器作Browser更佳。當然可能在Samba服務器啟動之前,網絡中都已經存在了Browser了,一般情況下不必重新進行推舉過程,讓網絡中的現有Browser繼續發揮作用。如果希望Samba服務器總是成為Browser,可以設置當Samba服務器啟動時,迫使網絡中重新進行推舉過程,這需要設定perfered master參數。
  通常Samba能夠勝任master Browser的角色,然而在多個子網的情況時,網絡上就會存在Local master Browser和Domain master Browser。以上的設置只能使Samba成為 Local master Browser,缺省Samba並不參加Domain master Brower的推舉。設置Samba服務器成為Domain master Browser就必須使用domain master參數進行設置,這對於使用工作組方式進行跨子網浏覽意義重大。
  但是如果網絡使用的是NT的域方式,就要使用NT的域控制器作為Domain master Browser ,不要設置與NT域控制器同一個子網中的Samba服務器的domain brower與browser功能,以免它和域控制器競爭。不讓Samba服務器和NT域控制器競爭的原因是由於Windows NT中域控制器還涉及域認證(不是認證域用戶,而是認證域上的合法成員計算機),SMB協議中各種復雜功能交錯混合,浏覽和認證兩種不同的功能竟也混合在一起。由於域控制器完成的域認證任務,Samba服務器不能夠完成,因此為了避免與NT域控制器相互沖突,最好使用域控制器作Domain master Browser。
  讓Samba服務器了解當前域中存在的域控制器的方法是指定在設置文件中指定域基本控制器PDC(primary Domain Controller)的NetBIOS名字,這需要使用domain controller參數進行設置。
# Enable this if you want Samba to be a domain logon server for
# Windows95 workstations.
; domain logons = yes

# if you enable domain logons then you may want a per-machine or
# per user logon script
# run a specific logon batch file per workstation (machine)
; logon script = %m.bat
# run a specific logon batch file per username
; logon script = %U.bat

# Where to store roving profiles (only for Win95 and WinNT)
# %L substitutes for this servers netbios name, %U is username
# You must uncomment the [Profiles] share below
; logon path = \\%L\Profiles\%U


  當用戶通過一台Windows 9x客戶機使用用戶級認證訪問網絡時,他可以選擇登錄進網絡中的域。這意味著他不但要在SMB服務器中進行驗證,而且會執行服務器中相應目錄中的登錄腳本,以自動執行一些相關設置。通常這種登錄功能是由Windows NT服務器來執行的,然而Samba服務器也能完成這個任務,但必須設定domain logons 參數。此後就可以對不同的客戶計算機或不同用戶指定相應的登錄腳本。這個功能還必須要求在本配置文件後面設置 netlogon共享選項,以便客戶機能訪問相應的登錄腳本。
  除了登錄腳本之外,Windows NT中為了支持移動用戶在不同地點進行漫游,也提供了針對每個用戶的描述其使用環境的Profile文件,Samba服務器也可以通過logon path來支持對windows客戶機這種漫游能力的支持。這樣當Windows客戶機使用漫游功能的時候,客戶機會自動將用戶的配置文件保存到服務器上,此後每次登錄進域的時候都重新下載這個配置文件,設置Windows桌面環境。
# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server
; wins support = yes
# WINS Server - Tells the NMBD components of Samba to be a WINS Client
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
; wins server = w.x.y.z

# WINS Proxy - Tells Samba to answer name resolution queries on
# behalf of a non WINS capable client, for this to work there must be
# at least one WINS Server on the network. The default is NO.
; wins proxy = yes

# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups. The built-in default for versions 1.9.17 is yes,
# this has been changed in version 1.9.18 to no.
dns proxy = no


  上面的這些選項是用於設置NetBIOS名字解析方式,wins support選項使得nmdb能對外表現為一個NBNS服務器。wins server用於指定一個外部名字服務器的地址(可以為NT上的wins服務器或另一個Samba服務器),使得nmbd能用做NBNS客戶端,通過訪問該wins名字服務器解析NetBIOS名字。
  此外,還有一些不使用名字服務器進行解析的NetBIOS客戶,如果名字服務器位於另一個子網上,那麼它們就無法正確解析名字,而Samba可以使用wins proxy幫助它們使用名字服務器解析地址。例如一個WINS服務器在另一個子網上,本地子網內的Samba服務器配置了wins server的地址,其他Windows客戶沒有設置wins服務器地址,它們使用b-node廣播方式查詢名字,在這台Samba服務器設置了wins proxy能力之後,它就能代替wins服務器回應客戶請求。因此要用作wins代理,就必須本身能使用名字服務器進行解析,就要求先設置wins server參數。
  此外,NetBIOS名字解析也可以擴展到通過DNS查詢進行幫助,使用dns proxy設置就能讓Samba 服務器通過dns進行查詢,回應NetBIOS名字查詢請求。
[homes]個人目錄共享
#============================ Share Definitions ==============================
[homes]
comment = Home Directories
browseable = no
writable = yes


  [homes]部分使得每個Unix用戶通過SMB客戶登錄上來的時候,可以共享使用他自己的個人目錄。這個共享資源具備特別屬性,當用戶登錄上之後,共享名就不是homes,而是被服務器映射為用戶自己的標識符。
  設置這個特別的共享選項,就允許每個用戶訪問自己的個人目錄,而不必為每個用戶都配置一個共享資源部分。正由於系統會自動映射,因此就不需要定義要共享的文件目錄路徑,而在其它文件資源共享選項中,都需要使用path參數進行定義。
  由於Samba系統會自動將homes共享名改變為用戶的個人標識符,因此要設定browseable=no ,設置homes本身這個名字不出現在資源列表中。writable為用戶寫權限設置,由於是在用戶的個人目錄下,用戶可以具備寫權限。
[netlogon]與[Profiles]
# Un-comment the following and create the netlogon directory for Domain Logons
; [netlogon]
; comment = Network Logon Service
; path = /usr/local/samba/lib/netlogon
; guest ok = yes
; writable = no
; share modes = no


  當允許Samba服務器支持客戶的網絡登錄功能之後(設置domain logon),就需要設置[netlogon] 部分(刪除注釋符號),為guest用戶打開登錄路徑的訪問權限,以保證每個用戶都能訪問其自己的登錄腳本。由於需要使用guest對應的Unix帳戶訪問登錄腳本,這個登錄路徑及其下面的腳本文件都要允許該Unix帳號可以讀取。
  建立這個目錄之後,要設定正確的權限,並且創建這個目錄下對應各個計算機或用戶的登錄腳本,以提供給客戶正確的登錄腳本。
# Un-comment the following to provide a specific roving profile share
# the default is to use the user's home directory
;[Profiles]
; path = /usr/local/samba/profiles
; browseable = no
; guest ok = yes


  當支持Windows計算機漫游能力時,可以設定[Profiles]部分,並為相應的路徑建立目錄,及分配權限。來為Window計算機用戶設置桌面環境。
[Printers]打印機設置
# NOTE: If you have a BSD-style print system there is no need to
# specifically define each individual printer
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
# Set public = yes to allow user 'guest account' to print
guest ok = no
writable = no
printable = yes


  這個部分就用於設置將printcap中定義的所有打印機使用的相關設置,缺省情況下允許所有的合法客戶使用所有的打印機。BSD風格的打印系統,不需要任何設置就能正確共享所有的打印機,當然也可以使用printer參數指定具體的打印機以提供共享。而path參數定義的是打印機緩沖區的位置。guest ok、writeable用於設置正確的權限,而printable用於設置打印屬性。
  由於Windows的打印驅動已經將要打印的文件轉化為打印機支持的那種描述語言,因此這些打印文件不再需要任何過濾器進行轉換。因此需要在printcap中定義一個不使用任何過濾器、直接將打印文檔輸出到打印機端口的打印機選項。
其他專有共享目錄
# This one is useful for people to share files
;[tmp]
; comment = Temporary file space
; path = /tmp
; read only = no
; public = yes

# A publicly accessible directory, but read only, except for people in
# the "staff" group
;[public]
; comment = Public Stuff
; path = /home/samba
; public = yes
; writable = yes
; printable = no
; write list = @staff

# Other examples.
#
# A private printer, usable only by fred. Spool data will be placed in fred's
# home directory. Note that fred must have write access to the spool directory,
# wherever it is.
;[fredsprn]
; comment = Fred's Printer
; valid users = fred
; path = /homes/fred
; printer = freds_printer
; public = no
; writable = no
; printable = yes

# A private directory, usable only by fred. Note that fred requires write
# access to the directory.
;[fredsdir]
; comment = Fred's Service
; path = /usr/somewhere/private
; valid users = fred
; public = no
; writable = yes
; printable = no

# a service which has a different directory for each machine that connects
# this allows you to tailor configurations to incoming machines. You could
# also use the %U option to tailor it by user name.
# The %m gets replaced with the machine name that is connecting.
;[pchome]
; comment = PC Directories
; path = /usr/pc/%m
; public = no
; writable = yes

# A publicly accessible directory, read/write to all users. Note that all files
# created in the directory by users will be owned by the default user, so
# any user with access can delete any other user's files. Obviously this
# directory must be writable by the default user. Another user could of course
# be specified, in which case all files would be owned by that user instead.
;[public]
; path = /usr/somewhere/else/public
; public = yes
; only guest = yes
; writable = yes
; printable = no

# The following two entries demonstrate how to share a directory so that two
# users can place files there that will be owned by the specific users. In this
# setup, the directory should be writable by both users and should have the
# sticky bit set on it to prevent abuse. Obviously this could be extended to
# as many users as required.
;[myshare]
; comment = Mary's and Fred's stuff
; path = /usr/somewhere/shared
; valid users = mary fred
; public = no
; writable = yes
; printable = no
; create mask = 0765


  需要注意的是,當使用valid user用來設置合法訪問用戶時,或者使用wirte list定義具備寫權限的用戶時,都可以使用@staff的形式使用Unix的組名,這樣凡是屬於該staff組成員的用戶,都會具備相應權限。
  從這些例子中可以看到[global]用於設定全局參數,不會出現在資源列表中,[homes]用於設定個人目錄共享,其共享的名字映射為個人標識符而非homes,[printers]設定打印機共享,將共享所有的打印機名字,除了這些標題的共享名字與標題不同之外,其他每個標題都將代表一個共享資源的名字。
使用swat配置samba
swat 901/tcp


  出於安全的考慮,應該使用1024以下的端口,這是因為非root用戶也能占用1024以上的端口,如果使用 1024之上的端口,可能在某些情況下,普通用戶就可能通過欺騙的方法獲得管理員的口令。
swat stream tcp nowait root /usr/local/sbin/swat swat


  使用SWAT,設置Samba就非常容易,不再需要手工編輯設置文件,而可以直接使用浏覽器更改設置,並重新啟動Samba服務器。
Copyright © Linux教程網 All Rights Reserved