天天看點

怎麼運作smb伺服器,Smb伺服器搭建

安裝samba服務端

Step-1:為samba打開防火牆上的相應端口,運作以下指令:

iptables -I INPUT -p tcp --dport 137 -j ACCEPT

iptables -I INPUT -p udp --dport 137 -j ACCEPT

iptables -I INPUT -p tcp --dport 138 -j ACCEPT

iptables -I INPUT -p udp --dport 138 -j ACCEPT

iptables -I INPUT -p tcp --dport 139 -j ACCEPT

iptables -I INPUT -p udp --dport 139 -j ACCEPT

iptables -I INPUT -p tcp --dport 445 -j ACCEPT

iptables -I INPUT -p udp --dport 445 -j ACCEPT

service iptables save

service iptables restart

Step-2:将SELinux配置為permissive模式,運作以下指令:

setenforce 0 #零時生效,重新開機後失效

vim /etc/selinux/config

将上述檔案中的

SELINUX=enforcing

替換為

SELINUX=permissive或者SELINUX=disable

Step-3:安裝samba服務端,運作以下指令:

yum install -y samba

Step-4:配置smb.conf檔案,運作以下指令:

mv /etc/samba/smb.conf /etc/samba/smb.conf.bak

vi /etc/samba/smb.conf

上述配置檔案的内容如下所示:

[global]

##samba伺服器的工作組為WORKGROUP

workgroup = WORKGROUP

##samba伺服器的描述資訊

server string = Samba Server Version %v

##samba伺服器的NetBIOS名稱

netbios name = CentOS.Server

##samba伺服器的用戶端通路日志

log file = /var/log/samba/log.%m

##日志的最大尺寸為50 KB

max log size = 50

##使用tdbsam存儲使用者資訊

passdb backend = tdbsam

##使用使用者驗證的方式確定安全性

security = user

##映射匿名使用者通路

map to guest = bad user

guest account = nobody

[homes]

##共享目錄說明

comment = Home Directories

##有效使用者,此目錄在/home目錄中

valid users = %S

##在Windows的網絡共享中看不到此目錄

browseable = No

##此目錄可寫

writable = Yes

[private]

##共享目錄說明

comment = Demo Directory

##共享目錄路徑

path = /samba/private

##有效使用者

valid users = @user1

##在Windows的網絡共享中能夠看到此目錄

browseable = Yes

##此目錄不能匿名公開通路

public = No

##此目錄可寫

writable = Yes

[public]

##共享目錄說明

comment = Public Stuff

#共享目錄路徑

path = /samba/public

##在Windows的網絡共享中能夠看到此目錄

browseable = Yes

##此目錄可以公開匿名通路

public = Yes

##此目錄可寫

writable = Yes

Step-5:在系統中建立兩個使用者組和使用者,分别是user1和user2,運作以下指令:

groupadd user1

useradd -g user1 user1

passwd user1

groupadd user2

useradd -g user2 user2

passwd user2

注意:user1和user2的密碼都為password。

Step-6:在samba服務端建立兩個使用者,運作以下指令:

smbpasswd -a user1

smbpasswd -a user2

注意:user1和user2的samba通路密碼都為password。

Step-7:建立相應的目錄,并且設定通路權限,運作以下指令:

mkdir -p /samba/public

mkdir -p /samba/private

chmod -R 777 /samba

Step-8:配置和啟動samba服務,運作以下指令:

chkconfig smb on

chkconfig nmb on

service smb start

service nmb start

通過上述8個步驟的配置,在用戶端便能通路共享目錄了。user1和user2都能夠通路public目錄,具有讀寫權限;隻有user1能夠通路private目錄,具有讀寫權限;user1和user2的個人目錄不可見,隻能通過url進行通路,各自都具有讀寫權限。