標籤:samba
1 安裝
yum -y install samba
2 修改設定檔
vi /etc/samba/smb.conf
1)全域配置
[global]
workgroup = WORKGROUP #要訪問的電腦的工作群組名,windows一般預設都為這個
hosts allow = 127. 192.168.128. #去掉前面的分號,並修改能訪問的網段(注意,由於本地與虛擬機器是通過nat連網的,所以這裡的網段是虛擬機器的網段)
security = share #訪問的方式,share不要求輸入密碼,user需要使用者名稱和密碼
2)文檔最後添加共用的目錄,並且允許寫操作
[public]
comment = public Stuff
path = /home/samba
public = yes
writable = yes
3 建立共用檔案
mkdir /home/samba
4 修改共用檔案許可權
chmod 777 /home/samba
添加samba使用者
使用smbpasswd添加samba使用者,使用者必須是linux系統中已有的使用者,密碼則不必和系統使用者相同。
如果沒有,添加使用者先。
#useradd smb
# smbpasswd smb (在windows下訪問linux需要的密碼)
New SMB password:
Retype new SMB password:
Failed to find entry for user root.
Failed to modify password entry for user root
出現上面這個錯的原因是因為需要為root使用者建立一個使用者,使用smbpasswd –a root就可以解決了。
說明是沒有該使用者,請使用 -a 參數
OPTIONS
-a
This option specifies that the username following should be added to the local smbpasswd file, with the new
password typed (type <Enter> for the old password). This option is ignored if the username following
already exists in the smbpasswd file and it is treated like a regular change password command. Note that
the default passdb backends require the user to already exist in the system password file (usually
/etc/passwd), else the request to add the user will fail.
This option is only available when running smbpasswd as root.
解決方案:
加參數‘-a’:
# smbpasswd -a 使用者即可,如下:
# smbpasswd -a smb
New SMB password:
Retype new SMB password:
Added user root.
(5)修改/etc/samba/smb.conf,在其中添加:
[public]
valid users = smb(使用者名稱)
5 防火牆開放連接埠(或者是直接關閉 /etc/init.d/iptables stop)
1)開放連接埠
iptables -I INPUT -p udp --dport 137 -j ACCEPT
iptables -I INPUT -p udp --dport 138 -j ACCEPT
iptables -I INPUT -p tcp --dport 139 -j ACCEPT
iptables -I INPUT -p tcp --dport 445 -j ACCEPT
2)儲存配置
/etc/init.d/iptables save
3)重啟防火牆
/etc/init.d/iptables restart
selinux設定
預設的,SELinux禁止網路上對Samba伺服器上的共用目錄進行寫操作,即使你在smb.conf中允許了這項操作。 假設你已經配置了共用目錄/share並允許使用者進行讀寫,而你又不想關閉SELinux的話,可以試試以下操作:
程式碼:
#/usr/sbin/setsebool -P allow_smbd_anon_write=1 #chcon -t public_content_rw_t /home/samba
其中第一條語句設定SELinux允許存取標記了public_content_rw_t的內容,第二條語句把欲共用的/share目錄標記為public_content_rw_t。 附SELinux資料:selinux簡介SElinux 在linux核心層級上提供了一個靈活的強制存取控制系統(MAC),這個強制存取控制系統是建立在自由存取控制系統(DAC)之上的。
6 啟動samba服務
/etc/init.d/smb start
7 開機啟動
chkconfig smb on
本文出自 “過客煙雲” 部落格,請務必保留此出處http://272153545.blog.51cto.com/7245562/1606528
centos 6.4_32位不關閉防火牆的samba安裝