samba適合內網檔案分享權限設定。本教程適合ubuntu/Fedora系統。
1、查看是否已安裝。
# rpm -q samba
package samba is not installed
2、使用yum查詢軟體包
#yum list samba (查詢軟體包,得到可安裝的軟體包: samba.i686)
3、使用yum安裝 (一路選yes安裝完成)
# yum install samba.i686
啟動
service iptables stop
service smb start
service nmb start
smbd進程的作用是處理SMB請求包(139連接埠),負責驗證和檔案分享權限設定(重要)。nmdb(137 138連接埠)
systemctl
配置:
查詢安裝了哪些軟體包。
#rpm -qa|grep samba
找設定檔,到common的軟體包。
#rpm -q| samba-common-4.0.3.2 | grep smb.conf
找到了:/etc/samba/smb.conf
備份一下:
#cp samba.conf samba.conf.bak
【global】 全域
workgroup= 指定工作群組或域
server string = 描述
security = 指定安全模式 (share 無許可權驗證,user 有伺服器驗證(預設))
hosts allow = 限定主機訪問 (哪些主機可以訪問,哪些使用者)
使用ip網段 例如: 162.1.2.
log file = 指定記錄檔存放位置
具體配置:
帶 ; 分號開頭的注釋是有效配置,就是說把分號去掉,在做寫修改就行了。
1、配置hosts
我的配置,允許10.5.82. 網段的
hosts allow = 10.5.82.
2、security 大家可以自訂配置
【home】段, 共用使用者的宿主目錄
comment = 描述
browseable = no (沒有許可權訪問的目錄,不可見)
writable = yes
3、需要先添加使用者:
adduser sambatest
添加的samda使用者必須是系統使用者。
assdb backend = tdbsam passdb backend即使用者後台。有三種後台:smbpasswd、tdbsam和ldapsam。
Sam即security account manager。
1. smbpasswd:該方式是使用smb工具smbpasswd給系統使用者(真實使用者或者虛擬使用者)設定一個Samba 密碼,用戶端就用此密碼訪問Samba資源。smbpasswd在/etc/samba中,有時需要手工建立該檔案。
2. tdbsam:使用資料庫檔案建立使用者資料庫。資料庫檔案叫passdb.tdb,在/etc/samba中。passdb.tdb使用者資料庫可使用smbpasswd –a建立Samba使用者,要建立的Samba使用者必須先是系統使用者。也可使用pdbedit建立Samba賬戶。pdbedit參數很多,列出幾個主要的:
pdbedit –a username:建立Samba賬戶。
pdbedit –x username:刪除Samba賬戶。
pdbedit –L:列出Samba使用者列表,讀取passdb.tdb資料庫檔案。
pdbedit –Lv:列出Samba使用者列表詳細資料。
pdbedit –c “[D]” –u username:暫停該Samba使用者帳號。
pdbedit –c “[]” –u username:恢複該Samba使用者帳號。
3. ldapsam:基於LDAP賬戶管理方式驗證使用者。首先要建立LDAP服務,設定“passdb backend = ldapsam:ldap://LDAP Server”
通過windows來訪問:
在運行中輸入:\\linux地址
\\192.168.175.130
會彈出對話方塊,輸入使用者名稱和密碼。
登入成功後如果不能訪問:
#setsebool -P samba_enable_home_dirs on
[global]workgroup = MYGROUPserver string = Samba Server Version %v;netbios name = MYSERVER;interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24hosts allow = 127. 192.168.12. 192.168.13. 10.5.82. 192.168. 10.5.# logs split per machinelog file = /var/log/samba/log.%m# max 50KB per log file, then rotatemax log size = 50security = user;passdb backend = tdbsam;security = domain;passdb backend = tdbsam;realm = MY_REALM;password server = <NT-Server-Name>;security = user;passdb backend = tdbsam;domain master = yes ;domain logons = yes# the login script name depends on the machine name;logon script = %m.bat# the login script name depends on the unix user used;logon script = %u.bat;logon path = \\%L\Profiles\%u# disables profiles support by specifing an empty path;logon path = ;add user script = /usr/sbin/useradd "%u" -n -g users;add group script = /usr/sbin/groupadd "%g";add machine script = /usr/sbin/useradd -n -c "Workstation (%u)" -M -d /nohome -s /bin/false "%u";delete user script = /usr/sbin/userdel "%u";delete user from group script = /usr/sbin/userdel "%u" "%g";delete group script = /usr/sbin/groupdel "%g";local master = no;os level = 33;preferred master = yes;wins support = yes;wins server = w.x.y.z;wins proxy = yes;dns proxy = yesload printers = yescups options = raw;printcap name = /etc/printcap#obtain list of printers automatically on SystemV;printcap name = lpstat;printing = cups;map archive = no;map hidden = no;map read only = no;map system = no;store dos attributes = yes[homes]comment = Home Directoriesbrowseable = nowritable = yes;valid users = %S;valid users = MYDOMAIN\%S[printers]comment = All Printerspath = /var/spool/sambabrowseable = noguest ok = yeswritable = yesprintable = yes;[netlogon];comment = Network Logon Service;path = /var/lib/samba/netlogon;guest ok = yes;writable = no;share modes = no;[Profiles];path = /var/lib/samba/profiles;browseable = no;guest ok = yes;[public];comment = Public Stuff;path = /home/samba;public = yes;writable = yes;printable = no;write list = +staff[myshare]comment = gaotong's filespath = /home/sharepublic = yeswirtable = yesprintable = no