對於linux與windows共享,可以用Samba軟件實現,Samba是一套免費的開源軟件,可以在linux或其他類unix操作系統上實現windows域控制器,文件服務,打印服務等。
Samba實現了windows系統所使用的核心網絡協議:SMB(Server Message Block)。
Samba可以提供如下功能:
活動目錄服務(Active Directory Server, ADS)
主域控制器(Primary Domain Controller, PDC)
共享目錄
共享打印機
Samba是一個高性能的服務軟件,只需要更低的硬件就可以實現windows server相同的性能。
1. 安裝samba
檢查是否已安裝samba:linux:/ # rpm -q samba
如果沒有安裝顯示:package samba is not installed
如果已安裝顯示為:samba-3.0.4-1.22 (或其他版本)
插入CD3,進入linux:/ # cd /media/cdrom/suse/i586,找到需要安裝的samba

上圖中帶黃色框的為主要安裝文件,使用命令:linux:/ # rpm -ivh samba-3.0.4-1.22.i586.rpm 進行安裝samba。
2. 配置samba
2.1 建立共享文件夾
安裝完成后,用上述命令查看是否安裝,進入home文件夾下建立一個共享文件夾:share。
2.2 在yast里面設置server服務器
打開yast設置進入網絡服務,network services->samba server,選擇share->add,共享名為:share,description:server,share path:/home/share


2.3 創建用戶並加入samba用戶組
linux:/ # useradd -m smb //添加系統用戶
linux:/ # passwd smb //輸入用戶密碼
密碼輸入完成后,把smb用戶加入到samba用戶組中,linux:/ # smbpasswd -a smb //將剛才建立的用戶加入samba用戶組,並輸入訪問密碼。
密碼輸入完成后,對新建的共享文件夾目錄share賦予smb用戶的權限,linux:/ # chown smb /home/share,linux:/ # chmod 777 /home/share
2.4 配置smb.conf
linux:/ # vi /etc/samba/smb.conf
修改【global】下的security=user,說明:設置用戶訪問samba server的驗證方式,一共有四種驗證方式。
a. share:用戶訪問samba server不需要提供用戶名和密碼,安全性較低。
b. user:samba server共享目錄只能被授權的用戶訪問,由samba server負責檢查賬號和密碼的正確性。賬號和密碼要在samba server中建立。
c. server:依靠其他windows NT/2000 或samba server來驗證用戶的賬號和密碼,是一種代理驗證。此種安全模式下,系統管理員可以把所有的windows用 戶和口令集中到一個NT系統上,使用windows NT進行samba認證,遠程服務器可以自動認證全部用戶和口令,如果認證失敗,samba將使用用戶級安全模式作為替代的方式。
d. domain:域安全級別,使用主域控制器(PDC)來完成認證。
在2.2步之后,smb.conf文件下面自動添加了【share】段名。
[share]
.........
Writable = Yes
Browsable = Yes
Valid users =smb //由於security 為user則需要寫上允許的用戶名
Guest ok = on //打開guest用戶
修改完成后保存文件。
2.5 重啟samba服務器
linux:/ # /etc/rc.d/smb restart
3. windows訪問samba服務器
運行里輸入linux IP,輸入用戶名和密碼。
若是打開了防火牆需要把smb添加到trust 列表中。
可以通過setup命令進入配置
可以直接通過iptable來配置訪問(這個更安全)
若是SElinux設置為enforcing
則設置如下:
//以下文字位於/etc/samba/smb.conf
# SELINUX NOTES:
#
# If you want to use the useradd/groupadd family of binaries please run:
# setsebool -P samba_domain_controller on
#
# If you want to share home directories via samba please run:
# setsebool -P samba_enable_home_dirs on //設置SElinux 策略允許用戶訪問自己的主目錄
##//為設置為共享的文件夾設置SELinux安全上下文(context)
# If you create a new directory you want to share you should mark it as
# "samba-share_t" so that selinux will let you write into it.
# Make sure not to do that on system directories as they may already have
# been marked with othe SELinux labels.
#
# Use ls -ldZ /path to see which context a directory has
# Set labels only on directories you created!
# To set a label use the following: chcon -t samba_share_t /path
#
# If you need to share a system created directory you can use one of the
# following (read-only/read-write):
# setsebool -P samba_export_all_ro on
# or
# setsebool -P samba_export_all_rw on
#
# If you want to run scripts (preexec/root prexec/print command/...) please
# put them into the /var/lib/samba/scripts directory so that smbd will be
# allowed to run them.
# Make sure you COPY them and not MOVE them so that the right SELinux context
# is applied, to check all is ok use restorecon -R -v /var/lib/samba/scripts
通過以上設置就可以在開啟防火牆、SElinux的情況下正常訪問基於REHL的samba服務器
