samba服务建起了Linux和Windows之间的桥梁,实现了不同系统之间的互通,如复制文件、实现不同操作系统的资源共享。在实际应用中,可以将samba服务器架设成一个强大的文件服务器。
在本篇文章中,将实现Linux和Linux之间、Linux和Windows之间的samba服务。
地址规划
OS | IP |
rehl9.0 | 192.168.96.171 |
OpenEuler | 192.168.96.251 |
windowserver2016 | 192.168.96.248 |
准备工作
rehl9.0
1、配置yum仓库
[root@localhost ~]# cat /etc/yum.repos.d/dvd.repo
[Baseos]
name=BaseOS
baseurl=file:///mnt/cdrom/BaseOS
enabled=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=file:///mnt/cdrom/AppStream
enabled=1
gpgcheck=0
验证
[root@localhost ~]# dnf makecache
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
BaseOS 2.7 MB/s | 2.7 kB 00:00
AppStream 2.7 MB/s | 2.8 kB 00:00
Metadata cache created.
2、安装samba服务端软件包
[root@localhost ~]# dnf install samba*
验证
[root@localhost ~]# rpm -qa | grep samba
samba-common-4.15.5-105.el9_0.noarch
samba-client-libs-4.15.5-105.el9_0.x86_64
samba-common-libs-4.15.5-105.el9_0.x86_64
samba-libs-4.15.5-105.el9_0.x86_64
samba-winbind-modules-4.15.5-105.el9_0.x86_64
samba-client-4.15.5-105.el9_0.x86_64
samba-4.15.5-105.el9_0.x86_64
python3-samba-4.15.5-105.el9_0.x86_64
samba-common-tools-4.15.5-105.el9_0.x86_64
samba-winbind-4.15.5-105.el9_0.x86_64
samba-winbind-clients-4.15.5-105.el9_0.x86_64
samba-winbind-krb5-locator-4.15.5-105.el9_0.x86_64
samba-vfs-iouring-4.15.5-105.el9_0.x86_64
samba-krb5-printing-4.15.5-105.el9_0.x86_64
samba-winexe-4.15.5-105.el9_0.x86_64
OpenEuler
1、 安装samba客户端软件包
[root@localhost ~]# dnf install samba-client cifs-utils -y
samba-client: 提供samba服务
cifs-utils: 提供文件共享服务
正式工作
rhel9.0
修改samba配置文件/etc/samba/smb.conf
原配置文件
[global]
workgroup = WORKGROUP #工作组名称,注意如果要与windows相通,工作组名称要一致
security = user #安全验证方式,默认即可
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
include = /etc/samba/usershares.conf
[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 = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
workgroup
在windows主机上,查看
编辑
有可能你的配置文件里面是SAMBA工作组名
添加此条目进配置文件
[public]
comment =public #描述信息
path= /share #要共享出去的目录
writable= yes #允许读写
read only = no #关闭只读
browseable = yes #信息网络可见
valid users = samba01 #审核访问用户
在文件中,我们规划了要共享的目录,要创建的用户,现在将其创建出来
[root@localhost samba]# mkdir /share
[root@localhost samba]# useradd samba01
[root@localhost samba]# echo redhat | passwd --stdin samba01
Changing password for user samba01.
passwd: all authentication tokens updated successfully.
[root@localhost samba]# smbpasswd -a samba01
New SMB password:
Retype new SMB password:
Added user samba01.
注意,在你添加samba账号的时候,最好密码和samba用户保持一致
修改samba目录权限,保证共享出去的时候可以正常使用
[root@localhost ~]# echo redhat > /share/file.txt
[root@localhost ~]# chmod 777 -R /share/
[root@localhost ~]# chown samba01:samba01 -R /share/file.txt
关闭防火墙或者放行服务
关闭
[root@localhost samba]# systemctl stop firewalld
[root@localhost samba]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
放行
[root@localhost samba]# firewall-cmd --add-service=samba --permanent
success
[root@localhost samba]# firewall-cmd --reload
success
关闭Selinux,或者修改文件标签
关闭
[root@localhost ~]# setenforce 0
修改标签
[root@localhost ~]# chcon -t samba_share_t /share/file.txt -R
重启samba服务
[root@localhost ~]# systemctl restart smb
[root@localhost ~]# systemctl enable smb
Created symlink /etc/systemd/system/multi-user.target.wants/smb.service → /usr/lib/systemd/system/smb.service.
OpenEuler
列出目标主机的共享目录
[root@localhost ~]# smbclient -L 192.168.96.171 -U samba01%redhat
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
public Disk public
IPC$ IPC IPC Service (Samba 4.15.5)
samba01 Disk Home Directories
SMB1 disabled -- no workgroup available
以命令行共享访问
[root@localhost ~]# smbclient //192.168.96.171/public -U samba01%redhat
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Fri Sep 27 12:49:12 2024
.. D 0 Fri Sep 27 12:44:33 2024
file.txt N 7 Fri Sep 27 12:49:12 2024
100101372 blocks of size 1024. 94965448 blocks available
在当前主机上挂载该目录
[root@localhost ~]# mkdir /mnt/smbshare
[root@localhost ~]# mount -t cifs //192.168.96.171/public /mnt/smbshare -o username=samba01
标签:samba,4.15,配置,el9,服务器,root,localhost,105
From: https://blog.51cto.com/u_16900089/12220587