紅帽7 Samba服務實現文件共享
阿新 • • 發佈:2018-11-13
group sed rip 定向 class width data solution har
Samba 文件共享服務
首先需要先通過Yum 軟件倉庫來安裝 Samba 服務程序(Samba 服務程序的名字也恰巧是軟件包的名字)
[root@localhost ~]# yum install samba Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Resolving DependenciesView Code--> Running transaction check ---> Package samba.x86_64 0:4.1.1-31.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size================================================================================ Installing: samba x86_64 4.1.1-31.el7 rhel7 527 k Transaction Summary ================================================================================ Install 1 Package Total download size:527 k Installed size: 1.5 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : samba-4.1.1-31.el7.x86_64 1/1 rhel7/productid | 1.6 kB 00:00 Verifying : samba-4.1.1-31.el7.x86_64 1/1 Installed: samba.x86_64 0:4.1.1-31.el7 Complete!
去除Samba服務主配置文件中的註釋信息,先把主配置文件改個名字,然後使用 cat 命令讀入主配置文件,再在 grep 命令後面添加-v 參數(反向選擇),分別去掉所有以井號(#)和分號(;)開頭的註釋信息行,對於剩余的空白行可以使用^$參數來表示並進行反選過濾,最後把過濾後的可用參數信息通過重定向符覆蓋寫入到原始文件名稱中。
[root@localhost ~]# mv /etc/samba/smb.conf /etc/samba/smb.conf_bak [root@localhost ~]# cat /etc/samba/smb.conf_bak | grep -v "#" | grep -v ";" | grep -v "^$" > /etc/samba/smb.conf [root@localhost ~]# cat /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 [homes] comment = Home Directories browseable = no writable = yes [printers] comment = All Printers path = /var/spool/samba browseable = no guest ok = no writable = no printable = yes
Samba服務程序中的參數以及作用
[global] | #全局參數。 | |
workgroup = MYGROUP | #工作組名稱 | |
server string = Samba Server Version %v | #服務器介紹信息,參數%v為顯示SMB版本號 | |
log file = /var/log/samba/log.%m | #定義日誌文件的存放位置與名稱,參數%m為來訪的主機名 | |
max log size = 50 | #定義日誌文件的最大容量為50KB | |
security = user | #安全驗證的方式,總共有4種 | |
#share:來訪主機無需驗證口令;比較方便,但安全性很差 | ||
#user:需驗證來訪主機提供的口令後才可以訪問;提升了安全性 | ||
#server:使用獨立的遠程主機驗證來訪主機提供的口令(集中管理賬戶) | ||
#domain:使用域控制器進行身份驗證 | ||
passdb backend = tdbsam | #定義用戶後臺的類型,共有3種 | |
#smbpasswd:使用smbpasswd命令為系統用戶設置Samba服務程序的密碼 | ||
#tdbsam:創建數據庫文件並使用pdbedit命令建立Samba服務程序的用戶 | ||
#ldapsam:基於LDAP服務進行賬戶驗證 | ||
load printers = yes | #設置在Samba服務啟動時是否共享打印機設備 | |
cups options = raw | #打印機的選項 | |
[homes] | #共享參數 | |
comment = Home Directories | #描述信息 | |
browseable = no | #指定共享信息是否在“網上鄰居”中可見 | |
writable = yes | #定義是否可以執行寫入操作,與“read only”相反 | |
[printers] | #打印機共享參數 | |
comment = All Printers | ||
path = /var/spool/samba | #共享文件的實際路徑(重要)。 | |
browseable = no | ||
guest ok = no | #是否所有人可見,等同於"public"參數。 | |
writable = no | ||
printable = yes |
配置共享資源
用於設置 Samba 服務程序的參數以及作用
參數 | 作用 |
[database] | 共享名稱為database |
comment = Do not arbitrarily modify the database file | 警告用戶不要隨意修改數據庫 |
path = /database | 共享目錄為/database |
public = no | 關閉“所有人可見” |
writable = yes | 允許寫入操作 |
紅帽7 Samba服務實現文件共享