1. 程式人生 > >通過Samba服務實現Linux檔案共享到Windows

通過Samba服務實現Linux檔案共享到Windows

1.用yum命令安裝Samba服務
# yum install samba

 

2.配置訪問共享資源的使用者(如root,該賬戶一定要本來就在當前系統就存在的,我們用的root這肯定存在了)
# pdbedit -a -u root (會提示我們輸入密碼和確認密碼,注意此處的輸入密碼是輸入該賬戶在Samba服務資料庫中的密碼,這和root賬戶的系統密碼是不一樣的概念,我是設定的一樣的)

 

3.建立共享目錄同時賦予訪問共享資源使用者對該檔案的許可權。

# mkdir /home/database --建立目錄
# chown -Rf root:root /home/database --賦許可權
# semanage fcontext -a -t samba_share_t /home/database --修改 database 目錄的 SELinux 安全上下文
# restorecon -Rv /home/database --恢復SELinux檔案屬性,使上面修改操作立刻生效

 

4.設定 SELinux 服務與策略,使其允許通過 Samba 服務程式訪問普通使用者家目錄。(由於我們使用的是root使用者,所以就算我們執行了這一步操作也無許可權訪問root目錄)
# getsebool -a | grep samba --檢視Samba 服務程式相關的 SELinux 域策略
# setsebool -P samba_enable_home_dirs on --允許通過 Samba 服務程式訪問普通使用者家目錄

 

5.修改Samba 服務程式的主配置檔案,我們只需要改[global]這一個引數,和新建一個[database]引數就行,其他不用動,劉遄老師說可以刪掉[homes]和[printers]引數,這裡我是沒有刪。
# vim /etc/samba/smb.conf
[global]
workgroup = MYGROUP
server string = Samba Server Version %v
log file = /var/log/samba/log.%m
max log size = 50
security = user
passdb backend = tdbsam
load printers = yes
cups options = raw
[database]
comment = Do not arbitrarily modify the database file
path = /home/database
public = no
writable = yes

 

6.重啟 smb 服務(Samba 服務程式在 Linux 系統中的名字為 smb)並清空 iptables 防火牆
# systemctl restart smb --重啟smb服務
# systemctl enable smb --使smb服務自動啟動
# iptables -F --清空iptables防火牆
# service iptables save --對iptables服務進行儲存(注1)

linux上的共享配置工作就已經完成,接下來就是去Windows上訪問試試了,開啟執行視窗輸入\\ip,再輸入我們配置的共享使用者:root再輸入密碼就可以訪問共享檔案夾了。

 


注1:如果輸入# service iptables save之後提示"The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl."
解決辦法:

1.先執行如下命令:

systemctl stop firewalld

systemctl mask firewalld

2.安裝iptables services

yum install iptables-services

3.設定開機啟動

systemctl enable iptables

4.重啟iptables service

systemctl restart iptables

5.執行儲存配置命令

service iptables save