2021-05-12 14:32:11
Linux基礎入門教學-Samba檔案共用服務
使用Samba檔案共用服務
Samba起源:
早期網路想要在不同主機之間共用檔案大多要用FTP協定來傳輸,但FTP協定僅能做到傳輸檔案卻不能直接修改對方主機的資料資料,這樣確實不太方便,於是便出現了NFS開原始檔共用程式:NFS(NetworkFile System)是一個能夠將多台Linux的遠端主機資料掛載到本地目錄的服務,屬於輕量級的檔案共用服務,不支援Linux與 Windows系統間的檔案共用。
隨後在1991年時大學生Tridgwell為了解決Linux與Windows系統之間共用檔案的問題,便開發出了SMB協定與Samba服務程式。
SMB(Server Messages Block)協定:實現區域網內檔案或印表機等資源共用服務的協定。
當時Tridgwell想要註冊SMBServer這個商標,但卻被因為SMB是沒有意義的字元被拒絕了,經過Tridgwell不斷翻看詞典,終於找到了一個拉丁舞蹈的名字——SAMBA,而這個熱情舞蹈的名字中又恰好包含了SMB(SAMBA),於是這便是Samba程式名字的由來。
Samba服務程式是一款基於SMB協定並由伺服器端和用戶端組成的開原始檔共用軟體,實現了Linux與Windows系統間的檔案共用
1 samba安裝
[root@linuxidc ~]# yum install samba cifs-utils -y
2 啟動服務加入開機自啟動
[root@linuxidc ~]# systemctl start smb
[root@linuxidc ~]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
[root@linuxidc ~]# ss -lntup | grep smb
tcp LISTEN 0 50 *:139 *:* users:(("smbd",pid=1095,fd=38))
tcp LISTEN 0 50 *:445 *:* users:(("smbd",pid=1095,fd=37))
tcp LISTEN 0 50 :::139 :::* users:(("smbd",pid=1095,fd=36))
tcp LISTEN 0 50 :::445 :::* users:(("smbd",pid=1095,fd=35))
3 設定samba
[root@linuxidc ~]# mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
[root@linuxidc ~]# cat /etc/samba/smb.conf.bak | grep -v "#" | grep -v ";" | grep -v "^$" > /etc/samba/smb.conf
[root@linuxidc ~]# cat /etc/samba/smb.conf
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = root
create mask = 0664
directory mask = 0775
4 修改組態檔如下
[root@linuxidc ~]# vim /etc/samba/smb.conf
[root@linuxidc ~]# cat /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[share]
comment = This is share /data/samba/share
path = /data/samba/share
public = no
writable = yes
5 新增一個使用者用於存取共用資源
[root@linuxidc ~]# useradd samba_user
[root@linuxidc ~]# usermod -s /sbin/nologin samba_user
[root@linuxidc ~]# pdbedit -L
[root@linuxidc ~]# pdbedit -a -u samba_user
new password:
retype new password:
Unix username: samba_user
NT username:
Account Flags: [U ]
User SID: S-1-5-21-351179206-2754336130-384069223-1000
Primary Group SID: S-1-5-21-351179206-2754336130-384069223-513
Full Name:
Home Directory: linuxidcsamba_user
HomeDir Drive:
Logon Script:
Profile Path: linuxidcsamba_userprofile
Domain: linuxidc
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: Wed, 06 Feb 2036 23:06:39 CST
Kickoff time: Wed, 06 Feb 2036 23:06:39 CST
Password last set: Tue, 14 Aug 2018 19:37:44 CST
Password can change: Tue, 14 Aug 2018 19:37:44 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
[root@linuxidc ~]# chown -Rf samba_user.samba_user /data/samba/share/
6 重新啟動服務測試
[root@linuxidc ~]# systemctl restart smb
7 發現windows不能存取所共用的內容,解決方法如下
[root@linuxidc ~]# iptables -F
[root@linuxidc ~]# firewall-cmd --permanent --add-service=samba
success
[root@linuxidc ~]# firewall-cmd --reload
success
[root@linuxidc ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
tmpreaper_use_samba --> off
use_samba_home_dirs --> off
virt_use_samba --> off
[root@linuxidc ~]# setsebool -P samba_enable_home_dirs on
[root@linuxidc ~]# setsebool -P samba_export_all_rw on
匿名存取成功
更多Samba相關教學見以下內容:
CentOS 7.2 安裝設定Samba伺服器 https://www.linuxidc.com/Linux/2017-03/141390.htm
VMWare 虛擬機器 Ubuntu 雙網絡卡 存取 samba 速度 翻倍 https://www.linuxidc.com/Linux/2013-06/85445.htm
samba安裝使用圖解 https://www.linuxidc.com/Linux/2017-03/141254.htm
CentOS7.2下原始碼搭建Samba檔案伺服器[原創] https://www.linuxidc.com/Linux/2017-06/144557.htm
如何在Ubuntu 16.04上安裝和設定Samba伺服器以進行檔案共用 https://www.linuxidc.com/Linux/2017-11/148194.htm
CentOS 7下Samba服務安裝與設定詳解 https://www.linuxidc.com/Linux/2017-11/148354.htm
Red Hat 6.5 下 Samba伺服器搭建 https://www.linuxidc.com/Linux/2017-07/145747.htm
如何在Ubuntu 17.10上使用System-Config-Samba https://www.linuxidc.com/Linux/2018-01/150493.htm
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx
本文永久更新連結地址:https://www.linuxidc.com/Linux/2018-09/154055.htm
相關文章