- 論壇徽章:
- 0
|
Samba簡明手冊
Illusion Chen
Samba簡介
Samba是Andrew Tridgell在1991年(和Linux誕生的時間接近)編寫的,當(dāng)時他想在他的DOS客戶機(jī)上mount Unix server的磁盤,但他發(fā)現(xiàn)無法同時使用Sun的NFS協(xié)議,于是,連Socket(套接字)都不熟悉的他開始嘗試自己在PC機(jī)上實現(xiàn)NFS,經(jīng)過不斷摸索,他開發(fā)了一個包監(jiān)聽程序來反向解析SMB協(xié)議,終于在自己的計算機(jī)上實現(xiàn)了NFS Mount。到1992年1月,他完成了0.1版,稱為Server 0.1。但由于得到了X終端,他放棄了進(jìn)一步的開發(fā)。直到1994年底, Andrew Tridgell需要在Windows PC連接Linux系統(tǒng),Adrew Tridgell才重新開始在Linux上開發(fā)Samba,以支持Windows的改變,增加了對ACL、LDAP協(xié)議、Windows DFS文件系統(tǒng)、信任關(guān)系等方面的支持。
(簡單來說,安裝samba之后可使Unix/linux server支持NetBIOS/NetBEUI協(xié)議的通信方式。)
Samba服務(wù)做什么
* 在網(wǎng)絡(luò)上共享文件目錄,就像文件服務(wù)器。
* 在網(wǎng)絡(luò)上共享打印機(jī)。
* 提供部分類似Windows PDC的用戶安全控制功能。包括域,信任關(guān)系等.
Samba下載安裝
Samba下載站點:
http://www.samba.org
ftp://ftp.samba.org
http://sunfreeware.com
Samba的可下載版本包括二進(jìn)制程序binary package、源碼版本。下載回來的壓縮包一般需要用gunzip,tar來解壓縮包。有的包在解壓縮后即可通過運行一個script來自動編譯生成軟件包,然后通過packageadd –d來安裝samba了。在solaris下,samba通常被安裝在/usr/local/samba下。
安裝
./configure (- -help/- -prefix=/dir)
./make (需要gcc等編譯工具或lib包等)
./make install
啟動Samba
一般在安裝samba包后,會在/etc/rc2.d目錄下建立一個啟動腳本.如果沒有,那我們也可以創(chuàng)建一個script,主要是做samba,smbd,nmbd的啟動.
- #!/bin/sh
- # ident "@(#)samba.server 1.0 96/06/19 TK" /* SVr4.0 1.1.13.1*/
- #
- # Please send info on modifications to knuutila@cs.utu.fi
- #
- # Changed 20031008
- # This file should have uid root, gid sys and chmod 744
- #
- ulimit -n 1024
- if [ ! -d /usr/bin ]
- then # /usr not mounted
- exit
- fi
- killproc() { # kill the named process(es)
- pid=`/usr/bin/ps -e |
- /usr/bin/grep -w $1 |
- /usr/bin/sed -e 's/^ *//' -e 's/ .*//'`
- [ "$pid" != "" ] && kill $pid
- }
- # Start/stop processes required for samba server
- case "$1" in
- 'start')
- #
- # Edit these lines to suit your installation (paths, workgroup, host)
- #
- /usr/local/samba/bin/smbd -D
- /usr/local/samba/bin/nmbd -D
- echo "Samba services started"
- ;;
- 'stop')
- killproc nmbd
- killproc smbd
- echo "Samba services stopped"
- ;;
- *)
- echo "Usage: /etc/init.d/samba.server { start | stop }"
- ;;
- esac
復(fù)制代碼
將它保存在/etc/rc2.d或/etc/rc3.d下,命名為S99samba.server即可。
配置Samba
1, 安全級別
samba的安全級別通常有三種:share、user/server、domain。
Share的級別最寬松,不需要用戶名和密碼。User則需要用戶名和密碼,server是把安全驗證任務(wù)交給另一個samba/NT server。而domain則是windows的域安全級別。
2, smbpasswd
smbpasswd是samba服務(wù)的一部分,當(dāng)root執(zhí)行smbpasswd時,它可以添加刪除samba用戶,或改變用戶的屬性。當(dāng)標(biāo)準(zhǔn)用戶執(zhí)行smbpasswd時,它可以改變或加密密碼。由于當(dāng)smbpasswd被標(biāo)準(zhǔn)用戶運行時是作為客戶端,所以smbd必須運行。
Smbpasswd使用的散列加密算法是很脆弱的,所以我們必須對smbpasswd文件及其所在的目錄加以限制,使之成為僅root可讀寫,以保證其安全性。
3, 域安全級別
samba server可以創(chuàng)建或加入域。
在加入域的時候,我們先在NT PDC上加入samba server的NetBIOS名字,成為合法帳號。在samba server上,停止samba服務(wù),執(zhí)行smbpasswd –j domain –r pdc,將samba server加入域。在成功加入域后,會提示如下信息:smbpasswd: Joined domain xxx,同時在smbpasswd文件所在目錄添加一個機(jī)器帳號文件,文件名格式為domain.sambaserver.mac.
在重新啟動samba進(jìn)程前,我們必須編輯smb.conf
security = domain
workgroup = domain
encrypt password = yes
password server=domainPDC1 domainPDC2
samba server在加入NT域后即可對NT用戶驗證,不過,samba需要將NT用戶映射到unix UID。
方法一:user map = /dir/file;指定一個映射文件,如文件中描述root = administrator admin,則用戶administrator/admin訪問時作為root看待。
方法二:將NT用戶遷移到unix上來。由于只是需要一個合法的UID,所以可以鎖定用戶密碼,將其shell環(huán)境設(shè)為空或/bin/false。(也可以通過結(jié)合LDAP來同步windows和unix帳戶。)
4,SWAT
SWAT是samba默認(rèn)安裝的組件。其默認(rèn)端口是901,可以通過web瀏覽方式來對samba進(jìn)行簡單的配置。配置的結(jié)果將保存在smb.conf中。但是對于較高的安全性和個性化需求,我們必須直接編輯smb.conf。
4, Smb.conf
通常smb.conf被放在/usr/local/samba/lib下。它的內(nèi)容格式為“參數(shù)=值”,以;或#為注釋。除了[global]被作為全局參數(shù)外,[homes],[printers]等其他的段都可以看作共享資源。在配置完成之后,可以運行testpram來測試smb.conf是否配制正確。
[global]:
workgroup = MYGROUP
定義該Samba服務(wù)器所在的工作組或者域(如果下面的security=domain的話)。
server string = MY Samba Server
設(shè)定機(jī)器的描述,當(dāng)我們通過網(wǎng)絡(luò)鄰居訪問的時候可以在備注里面看見這個內(nèi)容,而且還可以使用samba設(shè)定的變量。這里說一下samba定義的變量:
%S = 當(dāng)前服務(wù)名(如果有的話)
%P = 當(dāng)前服務(wù)的根目錄(如果有的話)
%u = 當(dāng)前服務(wù)的用戶名(如果有的話)
%g = 當(dāng)前用戶說在的主工作組
%U = 當(dāng)前對話的用戶名
%G = 當(dāng)前對話的用戶的主工作組
%H = 當(dāng)前服務(wù)的用戶的Home目錄
%v = Samba服務(wù)的版本號。
%h = 運行Samba服務(wù)機(jī)器的主機(jī)名
%m = 客戶機(jī)的NETBIOS名稱
%L = 服務(wù)器的NETBIOS名稱
%M = 客戶機(jī)的主機(jī)名
%N = NIS服務(wù)器名
%p = NIS服務(wù)的Home目錄
%R = 說采用的協(xié)議等級(值可以是CORE, COREPLUS, LANMAN1, LANMAN2,NT1)
%d = 當(dāng)前服務(wù)進(jìn)程的ID
%a = 客戶機(jī)的結(jié)構(gòu)(只能識別幾項:Samba,WfWg,WinNT,Win95)
%I = 客戶機(jī)的IP
%T = 當(dāng)前日期和時間
hosts allow = 網(wǎng)絡(luò)或者主機(jī)
這里可以設(shè)置允許訪問的網(wǎng)絡(luò)和主機(jī)IP,比如允許192.168.1.0/24和192.168.2.1/32訪問,就用host allow = 192.168.1. 192.168.2.1 127.0.0.1(網(wǎng)絡(luò)注意后面加”.”號,各個項目間用空格隔開,記得把本機(jī)也加進(jìn)去)
printcap name = printcapFile
到printcapFile(一般是/etc/printcap)這個文件中取得打印機(jī)的描述信息
load printers = yes/no
設(shè)定是否自動共享打印機(jī)而不用設(shè)置下面的[printer]一節(jié)的相關(guān)東西
printing = PrintSystemType
定義打印系統(tǒng)的類型,缺省是lprng,可選項有:bsd, sysv, plp, lprng, aix, hpux, qnx。
guest account = pcguest
定義游客帳號,而且需要把這個帳號加入/etc/passwd。
如不定義它就用缺省的nobody
log file = LogFileName
定義記錄文件的位置LogFileName(一般是用/var/log/samba/%m.log)
max log size = size
定義記錄文件的大小size(單位是KB,如果是0的話就不限大。
security = security_level
定義Samba的安全級別,按從低到高分為四級:share,user,server,domain。它們對應(yīng)的驗證方式如下:
share: 沒有安全性的級別,任何用戶都可以不要用戶名和口令訪問服務(wù)器上的資源。
user: samba的默認(rèn)配置,要求用戶在訪問共享資源之前資源必須先提供用戶名和密碼進(jìn)行驗證。
server: 和user安全級別類似,但用戶名和密碼是遞交到另外一個服務(wù)器去驗證,比如遞交給一臺NT服務(wù)器。如果遞交失敗,就退到user安全級。
domain: 這個安全級別要求網(wǎng)絡(luò)上存在一臺Windows的主域控制器,samba把用戶名和密碼遞交給它去驗證。
后面三種安全級都要求用戶在unix機(jī)器上也要系統(tǒng)帳戶。否則是不能訪問的。
password server = <NT-Server-Name>;
當(dāng)前面的security設(shè)定為server或者domain的時候才有必要設(shè)定它。
password level = n
這是設(shè)定針對一些SMB客戶像OS/2之類而設(shè)的,這樣的系統(tǒng)在發(fā)送用戶密碼的時候,會把密碼轉(zhuǎn)換成大寫再發(fā)送,這樣就和samba的密碼不一致,這個參數(shù)可以設(shè)定密碼里允許的大寫字母個數(shù),這樣samba就根據(jù)這個數(shù)目對接收到的密碼進(jìn)行大小寫重組,以重組過的密碼嘗試驗證密碼的正確性。n越大,組合的次數(shù)就越多,驗證時間就越長,安全性也會因此變得越低。例如n=2,用戶的密碼是abcd,但發(fā)送出去其實是ABCD,samba就會把這個ABCD進(jìn)行大小寫重組,組合后的結(jié)果可以是: Abcd, aBcd, abCd, abcD, abcd, ABcd, AbCd, AbcD,aBCd,aBcD,abCD。
所以如果沒有必要,就把n定為是零。這樣的話samba只嘗試兩次,一個是接收到的密碼,另一個嘗試的是這個密碼都是小寫的情況。
username level = n
這個是對于用戶名的情況,說明和上面一項類似。
encrypt passwords = yes/no
設(shè)置是否對密碼進(jìn)行加密,samba本身有一個密碼文件/etc/samba/smbpasswd,如果不對密碼進(jìn)行加密則在驗證會話期間客戶機(jī)和服務(wù)器之間傳遞的是明文密碼,samba直接把這個密碼和Linux里的/etc/samba/smbpasswd密碼文件進(jìn)行驗證。但是在Windows 95 OS/R2以后的版本和Windows NT SP3以后的版本缺省都不傳送明文密碼,要讓這些系統(tǒng)能傳送明文密碼必須在其注冊表里更改,比較麻煩,好的方法就是把這里的這個開關(guān)設(shè)置為yes。
smb passwd file = smbPasswordFile
設(shè)置存放samba用戶密碼的文件smbPasswordFile(一般是/etc/samba/smbpasswd)。
ssl CA certFile = sslFile
當(dāng)samba編譯的時候支持SSL的時候,需要指定SSL的證書的位置(一般在/usr/share/ssl/certs/ca-bundle.crt)。
unix password sync = yes/no
passwd program = /usr/bin/passwd %u
passwd chat = *New*UNIX*password* %n
*ReType*new*UNIX*password* %n
*passwd:*all*authentication*tokens*updated*successfully*
這三項設(shè)置能否從windows的應(yīng)用程序修改unix系統(tǒng)的用戶密碼
username map = UsermapFile
指定用戶映射文件(一般是/etc/samba/smbusers),當(dāng)我們在這個文件里面指定一行root = administrator admin的時候,客戶機(jī)的用戶是admin或者administrator連接時會被當(dāng)作用戶root看待。
include = MachineConfFile
指定對不同機(jī)器的連接采用不同的配置文件MachineConfFile(一般為了靈活管理使用/etc/samba/smb.conf.%m,由于采用了samba的變量,把配置文件和客戶機(jī)的NETBIOS名稱關(guān)聯(lián)起來,能很容易地控制這些客戶機(jī)的權(quán)限和設(shè)置)。
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
這個是網(wǎng)絡(luò)socket方面的一些參數(shù),能實現(xiàn)最好的文件傳輸性能。
相關(guān)的選項還有SO_KEEPALIVE、SO_REUSEADDR、SO_BROADCAST、IPTOS_LOWDELAY、IPTOS_THROUGHPUT、SO_SNDLOWAT(*)、SO_RCVLOWAT(*),帶*號的要指定數(shù)值。一般如果在本地網(wǎng)絡(luò),就只用IPTOS_LOWDELAY,如果是有一個本地網(wǎng)絡(luò)的,就用IPTOS_LOWDELAY TCP_NODELAY,如果是廣域網(wǎng)絡(luò),就試試IPTOS_THROUGHPUT。
interfaces = interface1 interface2
如果有多個網(wǎng)絡(luò)接口,就必須在這里指定。如interface = 192.168.12.2/24 192.168.13.2/24
remote browse sync = host(subnet)
這里指定瀏覽列表同步信息從哪里取得, 如果用host(比如192.168.3.25)或者整個子網(wǎng)(192.168.5.255)。
---------------------------------------------------------------------------------------------------------------------
*什么是瀏覽(Browse):
在SMB協(xié)議中,計算機(jī)為了訪問網(wǎng)絡(luò)資源,就需要了解網(wǎng)絡(luò)上存在的資源列表(例如在Windows下使用網(wǎng)絡(luò)鄰居查看可以訪問的計算機(jī)),這個機(jī)制就被稱為瀏覽(Browse)。雖然SMB協(xié)議中經(jīng)常使用廣播的方式,但如果每次都使用廣播的方式了解當(dāng)前的網(wǎng)絡(luò)資源(包括提供服務(wù)的計算機(jī)和各個計算機(jī)上的服務(wù)資源),就需要消耗大量的網(wǎng)絡(luò)資源和浪費較長的查找時間,因此最好在網(wǎng)絡(luò)中維護(hù)一個網(wǎng)絡(luò)資源的列表,以方便查找網(wǎng)絡(luò)資源。只有必要的時候,才重新查找資源,例如使用Windows下的查找計算機(jī)功能。
但沒有必要每個計算機(jī)都維護(hù)整個資源列表,維護(hù)網(wǎng)絡(luò)中當(dāng)前資源列表的任務(wù)由網(wǎng)絡(luò)上的幾個特殊計算機(jī)完成的,這些計算機(jī)被稱為Browser,這些Browser通過記錄廣播數(shù)據(jù)或查詢名字服務(wù)器來記錄網(wǎng)絡(luò)上的各種資源。
Browser并不是事先指定的計算機(jī),而是在普通計算機(jī)之間通過自動進(jìn)行的推舉產(chǎn)生的。不同的計算機(jī)可以按照其提供服務(wù)的能力,設(shè)置在推舉時具備的不同權(quán)重。為了保證一個Browser停機(jī)時網(wǎng)絡(luò)瀏覽仍然正常,網(wǎng)絡(luò)中常常存在多個Browser,一個為主Browser(Master Browser),其他的為備份Browser。
---------------------------------------------------------------------------------------------------------------------
remote announce = host(subnet)
指定這些機(jī)器向網(wǎng)絡(luò)宣告自己,而不是有Browser得到。
local master = yes/no
這個參數(shù)指定nmbd是否試圖成為本地主瀏覽器,默認(rèn)值是yes,如果設(shè)為no則samba服務(wù)器就永遠(yuǎn)都不會成為本地主瀏覽器。但即使設(shè)置了yes,也不等于samba服務(wù)器就會成為本地主瀏覽器。只是參與本地主瀏覽器選擇。
os level = n
n的值是個整數(shù),決定了nmbd是否有機(jī)會成為本地廣播區(qū)域的工作組里的本地主瀏覽器,默認(rèn)值是零,零則意味著nmbd失去瀏覽選擇。如果要nmbd更有機(jī)會成為本地主瀏覽器的話,可以設(shè)為65。
domain master = yes/no
這個參數(shù)讓nmbd成為一個域瀏覽器,取得各本地主瀏覽器的瀏覽列表,并將整個域的瀏覽列表遞交給各本地主瀏覽器。
preferred master = yes/no
這個參數(shù)指定nmbd是否是工作組里的首要的主瀏覽器,如果指定為yes,nmbd在啟動的時候就強(qiáng)制一個瀏覽選擇。
--------------------------------------------------------------------------------------------------------------------
Domain master和local master
工作組和域這兩個概念在進(jìn)行瀏覽時具備同樣的用處,都是用于區(qū)分并維護(hù)同一組瀏覽數(shù)據(jù)的多個計算機(jī)。事實上他們的不同在于認(rèn)證方式上,工作組中每臺計算機(jī)都基本上是獨立的,獨立對客戶訪問進(jìn)行認(rèn)證,而域中將存在一個(或幾個)域控制器,保存對整個域中都有效的認(rèn)證信息,包括用戶的認(rèn)證信息以及域內(nèi)成員計算機(jī)的認(rèn)證信息。瀏覽數(shù)據(jù)的時候,并不需要認(rèn)證信息,Microsoft將工作組擴(kuò)展為域,只是為了形成一種分級的目錄結(jié)構(gòu),將原有的瀏覽和目錄服務(wù)相結(jié)合,以擴(kuò)大Mircrosoft網(wǎng)絡(luò)服務(wù)范圍的一種策略。
工作組和域都可以跨越多個子網(wǎng),因此網(wǎng)絡(luò)中就存在兩種Browser,一種為Domain Master Browser,用于維護(hù)整個工作組或域內(nèi)的瀏覽數(shù)據(jù),另一種為Local Master Browser,用于維護(hù)本子網(wǎng)內(nèi)的瀏覽數(shù)據(jù),它和Domain Master Browser通信以獲得所有的可瀏覽數(shù)據(jù)。劃分這兩種Browser 主要是由于瀏覽數(shù)據(jù)依賴于本地網(wǎng)廣播來獲得資源列表,不同子網(wǎng)之間只能通過瀏覽器之間的交流能力,才能互相交換資源列表。
但是,為了瀏覽多個子網(wǎng)的資源,必須使用NBNS名字服務(wù)器的解析方式,沒有NBNS的幫助,計算機(jī)將不能獲得子網(wǎng)外計算機(jī)的NetBIOS名字。Local Master Browser也需要查詢NetBIOS名字服務(wù)器以獲得Domain Master Browser的名字,以相互交換網(wǎng)絡(luò)資源信息。
由于域控制器在域內(nèi)的特殊性,因此域控制器傾向于被用做Browser,主域控制器應(yīng)該被用作Domain Master Browser,他們在推舉時設(shè)置的權(quán)重較大。
----------------------------------------------------------------------------------------------------------------------
preserve case = yes/no
short preserve case = yes/no
指定拷貝DOS文件的時候保持大小寫,缺省是no
default case = lower/upper
所有的DOS文件的缺省是大寫還是小寫
case sensitive = yes/no
大小寫敏感,一般是no,不然會出現(xiàn)一些問題。
共享設(shè)置:
共享資源:
每個SMB服務(wù)器能對外提供文件或打印服務(wù),每個共享資源需要被給予一個共享名,這個名字將顯示在這個服務(wù)器的資源列表中。如果一個資源的名字的最后一個字母為$,則這個共享名就為隱藏共享,不能直接表現(xiàn)在瀏覽列表中,而只能通過直接訪問這個名字來進(jìn)行訪問。在SMB協(xié)議中,為了獲得服務(wù)器提供的資源列表,必須使用一個隱藏的資源名字IPC$來訪問服務(wù)器,否則客戶無法獲得系統(tǒng)資源的列表。
--------------------------------------------------------------------------------------------------------------------
[homes],在smb.conf文件中一般沒有對這個目錄的設(shè)定特定內(nèi)容比如路徑等。
當(dāng)客戶機(jī)發(fā)出服務(wù)請求時,就在smb.conf文件的其它部分查找特定內(nèi)容的服務(wù)。如果沒有發(fā)現(xiàn)這些服務(wù),并且提供了homes段時,那么就搜索密碼文件得到用戶的Home目錄。通過Homes段,Samba可以得到用戶的Home目錄并使之共享。
下面是這個段的最基本的幾個設(shè)置。
[homes]
comment=Home Directory
browseable=no
writable=yes
比較正常的共享的配置如下例:
[MyShare]
comment = grind’s file
path = /home/grind
allow hosts = host(subnet)
deny hosts = host(subnet)
writable = yes/no
user = user(@group)
valid users = user(@group)
invalid users = user(@group)
read list = user(@group)
write list = user(@group)
admin list = user(@group)
public = yes/no
hide dot files = yes/no
create mode = 0755
directory mode = 0755
sync always = yes/no
short preserve case = yes/no
preserve case = yes/no
case sensitive = yes/no
mangle case = yes/no
default case = upper/lower
force user = grind
wide links = yes/no
max connections = 100
delete readonly = yes/no
其中[]里面的MyShare指定共享名,一般就是網(wǎng)絡(luò)鄰居里面可以看見的文件夾的名字。
comment指的是對改共享的備注。
path指定共享的路徑,其中可以配合samba變量使用。比如你可以指定path=/data/%m,這樣如果一臺機(jī)器的NETBIOS名字是grind,它訪問MyShare這個共享的時候就是進(jìn)入/data/grind目錄,而對于NETBIOS名是glass的機(jī)器,則進(jìn)入/data/glass目錄。
allow hosts和deny hosts和前面的全局設(shè)置的方法一樣這里不再提及。
writeable指定了這個目錄缺省是否可寫,也可以用readonly = no來設(shè)置可寫。
user設(shè)置所有可能使用該共享資源的用戶,也可以用@group代表group這個組的所有成員,不同的項目之間用空格或者逗號隔開。
valid users指定能夠使用該共享資源的用戶和組。
invalid users指定不能夠使用該共享資源的用戶和組。
read list 指定只能讀取該共享資源的用戶和組。
write list指定能讀取和寫該共享資源的用戶和組。
admin list指定能管理該共享資源(包括讀寫和權(quán)限賦予等)的用戶和組。
public指明該共享資源是否能給游客帳號訪問,這個開關(guān)有時候也叫g(shù)uest ok,所以有的配置文件中出現(xiàn)guest ok = yes其實和public = yes是一樣的。
hide dot files指明是不是像unix那樣隱藏以“.”號開頭的文件。
create mode指明新建立的文件的屬性,一般是0755。
directory mode指明新建立的目錄的屬性,一般是0755。
sync always指明對該共享資源進(jìn)行寫操作后是否進(jìn)行同步操作。
short preserve case指明不管文件名大小寫。
preserve case指明保持大小寫。
case sensitive指明是否對大小寫敏感,一般選no,不然可能引起錯誤。
mangle case指明混合大小寫。
default case指明缺省的文件名是全部大寫還是小寫。
force user強(qiáng)制把建立文件的屬主是誰。如果我有一個目錄,讓guest可以寫,那么guest就可以刪除,如果我用force user= grind強(qiáng)制建立文件的屬主是grind,同時限制create mask = 0755,這樣guest就不能刪除了。
wide links指明是否允許共享外符號連接,比如共享資源里面有個連接指向非共享資源里面的文件或者目錄,如果設(shè)置wide links = no將使該連接不可用。
max connections = n設(shè)定同時連接數(shù)是n。
delete readonly指明能否刪除共享資源里面已經(jīng)被定義為只讀的文件。
有兩類特殊的共享,分別是光驅(qū)和打印機(jī)
光驅(qū)的共享設(shè)置:
[cdrom]
comment = grind’s cdrom
path = /mnt/cdrom
public = yes
browseable = yes
root preexec = /bin/mount -t iso9660 /dev/cd0 /mnt/cdrom
root postexec = /bin/umount /mnt/cdrom
這里root preexec指明了連接時用root的身份運行mount命令,而root postexec則指明了斷開時用root身份運行umount,有效實現(xiàn)了對光驅(qū)的共享。
打印機(jī)共享的設(shè)置:
[printers]
path = /var/spool/samba
writeable = no
guest ok = yes
printable = yes
printer driver = HP LaserJet 5L
這里printable指明該打印機(jī)可以打印, guest ok說明guest帳戶也能打印,path指明打印的臨時文件隊列放到/var/spool/samba目錄下。printer driver的作用是指明該打印機(jī)的類型,這樣我們在安裝網(wǎng)絡(luò)打印機(jī)的時候可以直接自動安裝驅(qū)動而不必選擇。
Smb.conf sample
Sample I: (solaris 8/Win nt domain)
- # this is the main Samba configuration file. You should read the
- # smb.conf(5) manual page in order to understand the options listed
- # 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]
- debug level = 0
- admin users = root
- netbios name = ufszx01
- # workgroup = NT-Domain-Name or Workgroup-Name
- ; workgroup = MYGROUP
- workgroup = UFSZX
- # Server string is the equivalent of the NT Description field
- ; server string = Samba Server
- server string = Samba Server on ufszx01
- # 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
- # the smb.conf man page
- ; hosts allow = 192.168.1. 192.168.2. 127.
- hosts allow = 192.168.8. 192.168.19.
- # 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
- 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
- # Uncomment this if you want a guest account, you must add this to /etc/passwd
- # otherwise the user "nobody" is used
- ; guest account = pcguest
- # this tells Samba to use a separate log file for each machine
- # that connects
- log file = /usr/local/samba/var/log.%m
- # Put a capping on the size of the log files (in Kb).
- max log size = 50
- # Security mode. Most people will want user level security. See
- # security_level.txt for details.
- ; security = user
- # security = server
- security = share
- # Use password server option only with security = server
- ; password server = <NT-Server-Name>;
- password server = ufszxnt01
- # Password Level allows matching of _n_ characters of the password for
- # all combinations of upper and lower case.
- ; password level = 8
- # 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
- # Unix users can map to different SMB User names
- ; username map = /etc/smbusers
- # 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
- ; include = /usr/local/samba/lib/smb.conf.%m
- # Most people will find that this option gives better performance.
- # See speed.txt and the manual pages for details
- socket options = TCP_NODELAY
- # 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
- # Configure remote browse list synchronisation here
- # request announcement to, or browse list sync from:
- # a specific host or from / to a whole subnet (see below)
- ; remote browse sync = 192.168.3.25 192.168.5.255
- # Cause this host to announce itself to local subnets here
- ; remote announce = 192.168.1.255 192.168.2.44
- # 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 = <NT-Domain-Controller-SMBName>;
- ;domain controller = exhkg
- # 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 Internet Name Serving Support Section:
- # WINS Support - Tells the NMBD component of Samba to enable it's WINS Server
- ; wins support = yes
- 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
- # Case Preservation can be handy - system default is _no_
- # NOTE: These can be set on a per share basis
- ; preserve case = no
- ; short preserve case = no
- # Default case is normally upper case for all DOS files
- ; default case = lower
- # Be very careful with case sensitivity - it can break things!
- ; case sensitive = no
- time server = true
- #============================ Share Definitions ==============================
- [homes]
- comment = Home Directories
- browseable = no
- writable = yes
- # 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
- # 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
- # NOTE: If you have a BSD-style print system there is no need to
- # specifically define each individual printer
- [printers]
- comment = All Printers
- path = /usr/spool/samba
- browseable = no
- # Set public = yes to allow user 'guest account' to print
- guest ok = yes
- writable = no
- printable = yes
- # 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
- [HP]
- path = /usr/spool/samba
- read only = No
- guest ok = Yes
- print ok = Yes
- share modes = No
- oplocks = No
- printer = HP
- [LOG]
- comment = LOG
- path = /icil/log/pc
- guest ok = yes
- writeable = yes
- create mode = 0666
- ;[TRAXON]
- ; comment = TRAXON
- ; path = /var/spool/uucppublic/traxon
- ; guest ok = yes
- ; writeable = yes
- ; create mode = 0777
- [TMP]
- comment = TMP
- path = /tmp
- guest ok = yes
- [CDROM]
- comment = CDROM
- path = /cdrom
- guest ok = yes
復(fù)制代碼
Sample II: (linux/ act as a PDC)
- # This is the main Samba configuration file. You should read the
- # smb.conf(5) manual page in order to understand the options listed
- # 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 made any basic syntactic errors.
- #
- #======================= Global Settings =====================================
- [global]
- # workgroup = NT-Domain-Name or Workgroup-Name
- workgroup = UFCMB
- netbios name = ufcmblx01
- # server string is the equivalent of the NT Description field
- server string = UFCMB Samba PDC Server
- # 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
- # the smb.conf man page
- ; hosts allow = 192.168.1. 192.168.2. 127.
- # if you want to automatically load your printer list rather
- # than setting them up individually then you'll need this
- ; printcap name = /etc/printcap
- load printers = no
- # It should not be necessary to spell out the print system type unless
- # yours is non-standard. Currently supported print systems include:
- # bsd, sysv, plp, lprng, aix, hpux, qnx
- ; printing = bsd
- # Uncomment this if you want a guest account, you must add this to /etc/passwd
- # otherwise the user "nobody" is used
- ; guest account = pcguest
- # this tells Samba to use a separate log file for each machine
- # that connects
- log file = /var/log/samba/log.%m
- # Put a capping on the size of the log files (in Kb).
- max log size = 50
- # 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 = <NT-Server-Name>;
- # Password Level allows matching of _n_ characters of the password for
- # all combinations of upper and lower case.
- ; password level = 8
- ; username level = 8
- # 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 passwd file = /usr/local/samba/private/smbpasswd
- # The following are needed to allow password changing from Windows to
- # update the Linux system password also.
- # NOTE: Use these with 'encrypt passwords' and 'smb passwd file' above.
- # NOTE2: You do NOT need these to allow workstations to change only
- # the encrypted SMB passwords. They allow the Unix password
- # to be kept in sync with the SMB password.
- unix password sync = Yes
- passwd program = /usr/bin/passwd %u
- passwd chat = *New* %n\n *ReType* %n\n
- # Unix users can map to different SMB User names
- username map = /usr/local/samba/private/smbusers
- # 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
- ; include = /etc/samba/smb.conf.%m
- # Most people will find that this option gives better performance.
- # See speed.txt and the manual pages for details
- socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
- # 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
- # Configure remote browse list synchronisation here
- # request announcement to, or browse list sync from:
- # a specific host or from / to a whole subnet (see below)
- ; remote browse sync = 192.168.3.25 192.168.5.255
- # Cause this host to announce itself to local subnets here
- ; remote announce = 192.168.1.255 192.168.2.44
- # 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 = yes
- # OS Level determines the precedence of this server in master browser
- # elections. The default value should be reasonable
- os level = 64
- # 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
- # 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
- logon script = icil.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 drive = Z:
- logon home = \\%N\%U
- logon path = \\%N\%U\profile
- # All NetBIOS names must be resolved to IP Addresses
- # 'Name Resolve Order' allows the named resolution mechanism to be specified
- # the default order is "host lmhosts wins bcast". "host" means use the unix
- # system gethostbyname() function call that will use either /etc/hosts OR
- # DNS or NIS depending on the settings of /etc/host.config, /etc/nsswitch.conf
- # and the /etc/resolv.conf file. "host" therefore is system configuration
- # dependant. This parameter is most often of use to prevent DNS lookups
- # in order to resolve NetBIOS names to IP Addresses. Use with care!
- # The example below excludes use of name resolution for machines that are NOT
- # on the local network segment
- # - OR - are not deliberately to be known via lmhosts or via WINS.
- name resolve order = wins lmhosts bcast
- # 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
- # Case Preservation can be handy - system default is _no_
- # NOTE: These can be set on a per share basis
- ; preserve case = no
- ; short preserve case = no
- # Default case is normally upper case for all DOS files
- ; default case = lower
- # Be very careful with case sensitivity - it can break things!
- ; case sensitive = no
- #============================ Share Definitions ==============================
- [homes]
- comment = Home Directories
- browseable = no
- writeable = yes
- # Un-comment the following and create the netlogon directory for Domain Logons
- [netlogon]
- comment = Network Logon Service
- path = /icil/home/netlogon
- guest ok = yes
- writable = no
- share modes = no
- # Un-comment the following to provide a specific roving profile share
- # the default is to use the user's home directory
- ;[profiles]
- ; path = /icil/home/profiles
- ; browseable = yes
- ; guest ok = yes
- ; create mask = 0600
- ; directory mask = 0700
- [DEPT]
- comment = Dept folder
- path = /icil/dept
- guest ok = yes
- writeable = yes
- create mode = 0666
- [GHOST]
- comment = Ghost image folder
- path = /ghost
- guest ok = yes
- writeable = yes
- create mode = 0666
復(fù)制代碼
Samba其他功能
1, Smbclient使用PC共享資源
smbclient '\\'${host}'\C$' -Uuser%"password" –W domain
操作方式類似FTP。具體操作方式略。
2,smbprint使用共享打印機(jī)(略)
Samba FAQ(略)
請查閱samba.org或Google以解決問題。
請參考以下站點來解決更深層次的問題:
http://www.samba.org[/code] |
|