Fedora9 Samba 服務器的搭建

 

1 安裝samba

[root@localhost ~]# yum –y install samba   ← 通過網絡安裝samba

 

2 添加samba用戶(用戶名稱叫“samba”)

[root@localhost ~]# adduser samba ← 添加用戶samba(系統自動在/home下創建samba文件夾)

[root@localhost ~]# smbpasswd -a samba ← 將系統用戶samba加入到 samba 用戶數據庫

New SMB password: ← 輸入該用戶用於登錄 samba 的密碼

Retype new SMB password: ← 再次確認輸入該密碼

 

3 配置samba

[root@localhost ~]# cd /etc/samba/ ← 進入samba配置目錄

[root@localhost ~]# cp smb.conf smbbak.conf ← 修改samba配置文件之前,首先對其進行備份(一個好習慣)

[root@localhost ~]# vi /etc/samba/smb.conf ← 打開配置文件

 

在配置文件的最後加入下列內容:

        [samba]

        comment = samba         ← samba描述

        path = /home/samba      ← 共享目錄

        public = no             ← 是否允許guest用戶訪問(相當於guest ok = yes/no)

        writable = yes          ← 是否可寫

        browseable = yes        ← 是否允許瀏覽(該行可以不寫)

        valid users = @samba    ← 訪問用戶(可以有多個,如:@samba @testuser ……)

 

4 開放防火牆端口

[root@localhost ~]# cd /etc/sysconfig/ ← 進入防火牆配置目錄

[root@localhost ~]# cp iptables iptablesbak ← 修改端口配置文件之前,首先對其進行備份(一個好習慣)

[root@localhost ~]# vi /etc/sysconfig/iptables ← 打開配置文件

 

在配置文件中加入下列內容:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT

-A INPUT -m state --state NEW -m udp -p udp --dport 137 -j ACCEPT

-A INPUT -m state --state NEW -m udp -p udp --dport 138 -j ACCEPT

 

[root@sample ~]# /etc/rc.d/init.d/iptables restart ← 重新啓動iptables,使新的規則生效

Flushing firewall rules:          [ OK ]
Setting chains to policy ACCEPT: filter     [ OK ]
Unloading iptables modules:       [ OK ]
Applying iptables firewall rules:      [ OK ]

 

5 啓動samba服務(含兩個守護進程:smb  nmb)

[root@sample ~]# chkconfig smb on ← 設置samba自啓動
[root@sample ~]# chkconfig --list smb ← 確認samba啓動標籤,確認2-5爲on的狀態

smb 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@sample ~]# chkconfig nmb on ← 設置nmb自啓動

[root@sample ~]# chkconfig --list nmb ← 確認nmb啓動標籤,確認2-5爲on的狀態(測試發現即使都爲off也不影響samba服務)

nmb 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@sample ~]# /etc/rc.d/init.d/smb start ← 啓動samba服務

Starting SMB services:       [ OK ]

[root@sample ~]# /etc/rc.d/init.d/nmb start ← 啓動nmb服務

Starting NMB services:       [ OK ]

 

6 Windows訪問samba服務

在運行中輸入 //192.168.0.8 (samba服務器IP)即可對samba共享目錄進行訪問。

 

【※】

問題1:在一切配置正常的情況下,經常出現客戶端訪問異常(無法成功登陸或可以看到共享文件夾卻無法進入等情況):

原因一:Fedora防火牆沒有允許samba端口訪問。

原因二:Federa中的安全子系統SELinux的原因,可將其關閉。

[root@localhost ~]# setenforce 0 ← 關閉SELinux

問題2:windows登陸samba時,提示samba不允許一個用戶使用一個以上用戶名與一個服務器或共享資源的多重連接。

解決辦法:windows運行中輸入命令行“net use * /del /y”後,重新登陸samba。

  

Fedora9 Samba server set up

Install samba
[root@localhost ~]# yum -y install samba ←through the network install samba

● Add samba user (user name called "samba")
[root@localhost ~]# adduser samba ← add users samba (the system automatically to create samba folder in the /home)
[root@localhost ~]# smbpasswd -a samba ← add the system user samba into samba user database
New SMB password: ← Enter the user password used to log on samba
Retype new SMB password: ← Enter the password again to confirm

● Configure samba
[root@localhost ~]# cd /etc/samba/ ← enter samba configuration directory
[root@localhost ~]# cp smb.conf smbbak.conf ← modify the samba configuration file, first back it up (good habit)
[root@localhost ~]# vi /etc/samba/smb.conf ← open the configuration file

Finally, in the configuration file add the following contents:
        [Samba]
        comment = samba ← samba description
        path = /home/samba ← shared directory
        public = no ← whether to allow guest user to access (equivalent to guest ok = yes / no)
        writable = yes ← whether to allow writing
        browseable = yes ← whether to allow browsing (the bank can not write)
        valid users = @samba ← the allowed user to access (you can have more than one

        such as: @samba @testuser ...)

● Open firewall ports
[root@localhost ~]# cd /etc/sysconfig/ ← enter the firewall configuration directory
[root@localhost ~]# cp iptables iptablesbak ← modify the port configuration file, first back it up (good habit)
[root@localhost ~]# vi /etc/sysconfig/iptables ← open the configuration file

In the configuration file to add the following:
-A INPUT-m state - state NEW-m tcp-p tcp - dport 139-j ACCEPT
-A INPUT-m state - state NEW-m tcp-p tcp - dport 445-j ACCEPT
-A INPUT-m state - state NEW-m udp-p udp - dport 137-j ACCEPT
-A INPUT-m state - state NEW-m udp-p udp - dport 138-j ACCEPT

[root@localhost ~]# /etc/rc.d/init.d/iptables restart ← restart iptables, the new rules take effect
Flushing firewall rules: [OK]
Setting chains to policy ACCEPT: filter [OK]
Unloading iptables modules: [OK]
Applying iptables firewall rules: [OK]

● Start the samba services(including two daemons: smb nmb)
[root@localhost ~]# chkconfig smb on ← set samba self-startup
[root@localhost ~]# chkconfig -list smb ← confirm the samba startup tab status, 2-5 are on
smb 0: off 1: off 2: on 3: on 4: on 5: on 6: off
[root@localhost ~]# chkconfig nmb on ← set from the start nmb
[root@localhost ~]# chkconfig -list nmb ←confirm the samba startup tab status, 2-5 are on
 (test found that even if all of them are off does not affect the samba service)
nmb 0: off 1: off 2: on 3: on 4: on 5: on 6: off
[root@localhost ~]# /etc/rc.d/init.d/smb start ← start the samba service
Starting SMB services: [OK]
[root@localhost ~]# /etc/rc.d/init.d/nmb start ← start nmb service
Starting NMB services: [OK]

● Windows access to samba server
Input //192.168.0.8 (samba server IP) in run can access the samba shared directory.

【※】

Q1:Although everything is OK, clients often access exception (unable to successfully log in or can see but can not access shared folders, etc.):
1st reason: Fedora firewall does not open samba port.
2nd reason: cause federa SELinux security subsystem, you can turn it off.
[root@localhost ~]# setenforce 0 ← set SELinux off

 

Q2:When login samba in windows, windows warns that does not allow multiple users to access same share in samba.
Solution: Inputting the command line "net use * / del / y" in windows run, re-login samba.
發佈了25 篇原創文章 · 獲贊 26 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章