允許 Linux、Unix 系統與 Windows 系統之間進行文件和打印機共享,使得不同操作系統的用戶能夠方便地訪問和共享資源,就像在同一局域網中的 Windows 計算機之間共享資源一樣。
server01安裝Samba服務器
[root@server ~]# rpm -qa | grep samba
[root@server admin]# mount ? /dev/cdrom ? /media/
[root@server admin]# dnf ?info ?samba? ? //如果安裝會看到對應信息
[root@server admin]# dnf ? clean ? all
[root@server admin]# dnf ?install ?samba ?-y? ? ? ? ? ? ? //安裝成功后再使用第一條命令[root@server admin]# systemctl start ? smb
[root@server admin]# systemctl enable ? smb
?
配置user服務器
[root@server ~]# vim ?/etc/samba/smb.conf
創建共享目錄,并在其中建立測試文件
[root@server ~]# mkdir ?/companydata/sales ?-p? ? ? ? ? ? ? ? ? ? ? //新建文件
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ????????????????????????? 帶-p選項:沒有父目錄會先創建
[root@server ~]# cd ?/companydata/
[root@server companydata]# ls? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //確認創建沒問題[root@server companydata]# cd sales/? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //切換到該目錄
[root@server sales]# touch ?test_share.tar? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //新建一個壓縮包
[root@server sales]# ls
test_share.tar
添加銷售部用戶和組并添加相應的Samba賬號
[root@server sales]# ?groupadd sales? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //創建用戶組sales
[root@server sales]# useradd -g sales ?sale1? ? ? ? ? ? ? ? ? //創建用戶sale1關聯組
[root@server sales]# useradd -g sales ?sale2? ? ? ? ? ? ? ? ?//創建用戶sale2關聯組[root@server sales]# useradd test_user1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//創建用戶test_user1
[root@server sales]# tail? /etc/passwd? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//查看
[root@server ~]# passwd sale1? (密碼qweasd123)
[root@server ~]# passwd sale2
[root@server ~]# passwd test_user1
為銷售部成員添加相應Samba賬號
[root@server ~]# smbpasswd -a ?sale1
New SMB password:qweasd123
Retype new SMB password:qweasd123
Added user sale1.[root@server ~]# smbpasswd -a ?sale2
修改Samba主配置文件
[root@server ~]# vim /etc/samba/smb.conf
[global]
? ? ? ? workgroup = SAMBA
? ? ? ? server string = File Server[sales]
? ? ? ? comment=sales
? ? ? ? path=/companydata/sales
? ? ? ? writable = yes
? ? ? ? browseable = yes
? ? ? ? valid users = @sales
設置本地權限、SELinux和防火墻
設置共享目錄的本地系統權限和屬組
[root@server ~]# chmod 770 ?/companydata/sales/ ?-R
[root@server ~]# chown ?:sales ?/companydata/sales/ ?-R
將SELinux的模式設置為寬容模式,用于測試
[root@server ~]# setenforce 0? ? ? ? ? ? ?//設置為寬容模式
[root@server ~]# getenforce? ? ? ? ? ? ? ?//查看
Permissive
在防火墻中允許Samba服務器
[root@server ~]# firewall-cmd --permanent --add-service=samba? ? ? ? //允許Samba
[root@server ~]# firewall-cmd --reload? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//重啟生效
[root@server ~]# firewall-cmd --list-all? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //查看服務
重新加載Samba服務并設置開機自啟
[root@server ~]# systemctl restart smb
[root@server ~]# systemctl enable smb
在Linux客戶端配置訪問Samba服務器
先安裝yum倉庫
[root@client ~]# cd /etc/yum.repos.d/
[root@client yum.repos.d]# rm ? -f ? ?*
[root@client yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo??https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@client yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e'/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@client yum.repos.d]# mount /dev/cdrom /media/
安裝Samba-client和cifs-utils
[root@client yum.repos.d]# dnf ?install ?samba-client ?cifs-utils ?-y
使用smbclient登錄
[root@client yum.repos.d]# smbclient -L ?192.168.111.100
[root@client yum.repos.d]# smbclient -L ?192.168.111.100 ? -U ?sale2%qweasd123
[root@client ~]# smbclient //192.168.111.100/sales ?-U ?sale2%qweasd123
smb: \> ls
smb: \> mkdir ?testdir
smb: \> lssmb: \> exit
?