歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> redhat如何安裝配置samba實現win共享linux主機目錄

redhat如何安裝配置samba實現win共享linux主機目錄

日期:2017/3/3 15:47:26   编辑:關於Linux

redhat安裝配置samba實現win共享linux主機目錄

一、安裝前准備

1、使用Samba服務器需要防火牆開放以下端口

UDP 137 UDP 138 TCP 139 TCP 445

#配置防火牆端口 www.2cto.com

[root@roothomes ~] 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@roothomes ~] /etc/rc.d/init.d/iptables restart

2、關閉CentOS6系統的 SELinux

[root@roothomes ~] vi /etc/selinux/config

#SELINUX=enforcing #注釋掉

#SELINUXTYPE=targeted #注釋掉

SELINUX=disabled #增加

#:wq 保存。

#重啟系統 www.2cto.com

[root@roothomes ~] shutdown -r now 或者 init 6

二、安裝Samba

1、檢查Samba服務包是否已安裝

[root@roothomes ~] rpm -qa | grep samba

samba-3.5.4-68.el6.x86_64

samba-common-3.5.4-68.el6.x86_64

samba-client-3.5.4-68.el6.x86_64

samba4-libs-4.0.0-23.alpha11.el6.x86_64

samba-winbind-clients-3.5.4-68.el6.x86_64

說明samba已經安裝,如果沒有安裝,運行下面命令安裝 [root@roothomes ~] yum install samba

2、配置samba

[root@roothomes ~] chkconfig smb on  #設置 Samba開機自動啟動

[root@roothomes ~] service smb start #啟動Samba服務

[root@roothomes ~] /etc/init.d/smb restart #重啟

[root@roothomes ~] /etc/init.d/smb stop #停止

[root@roothomes ~] cp /etc/samba/smb.conf /etc/samba/bak_smb.conf_bak #備份

[root@roothomes ~] cp /etc/samba/bak_smb.conf_bak /etc/samba/smb.conf #恢復

[root@roothomes ~] vi /etc/samba/smb.conf

[global] #找到這一行(全局設置標簽),在此行下面添加如下行:

workgroup = WORKGROUP #工作組名稱改為 Windows 網絡所定義的工作組名

server string = Samba Server #設置samba服務器的主機名稱

security = user #設置samba服務器安全級別為user,即以賬號和口令訪問

netbios name = SambaServer #設置Samba服務器訪問別名

#在配置文件的末尾添加以下自定義內容

[SambaServer] #在Windows網上鄰居中看到的共享目錄的名字

comment = SambaServer #在Windows網上鄰居中看到的共享目錄的備注信息

path = /home/SambaServer #共享目錄在系統中的位置

public = no #不公開目錄

writable = yes #共享目錄可以讀寫

valid users=SambaServer #只允許SambaServer用戶訪問

#保存配置

3、添加訪問linux共享目錄的賬號SambaServer

用戶家目錄為/home/SambaServer, 用戶登錄終端設為/bin/false(即使之不能登錄系統)

[root@roothomes ~] mkdir -p /home/SambaServer #建立SambaServer文件夾

[root@roothomes ~] cd /home/SambaServer

[root@roothomes ~] touch samba.txt #創建測試文件samba.txt

[root@roothomes ~] useradd SambaServer -d /home/SambaServer -s /bin/false

[root@roothomes ~] chown SambaServer:SambaServer /home/SambaServer -R

4、將用戶SambaServer添加入到Samba用戶數據庫,並設置登錄共享目錄的密碼為:123456

[root@roothomes ~] smbpasswd -a SambaServer

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

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

Added user SambaServer.

#備注:這裡設置的密碼是SambaServer用戶登錄該機的Samba共享的密碼,非登陸OS的密碼;

5、重啟Samba服務器

[root@roothomes ~] /etc/init.d/smb restart

6、浏覽共享信息

在Windows客戶端輸入 \\ip 或者 \\SambaServer #服務器別名

回車之後,會跳出來登錄框,輸入賬號SambaServer ,密碼123456 , 即可訪問共享目錄

問題:

如果無法訪問共享目錄的內容,請把防火牆停止;

[root@roothomes ~] service iptables stop

本欄目更多精彩內容:http://www.bianceng.cn/OS/Linux/

Copyright © Linux教程網 All Rights Reserved