羊蹓狼 发表于 2025-1-12 04:11:50

配置和管理samba服务器

samba服务建起了Linux和Windows之间的桥梁,实现了不同系统之间的互通,如复制文件、实现不同操作系统的资源共享。在实际应用中,可以将samba服务器架设成一个强大的文件服务器。
在本篇文章中,将实现Linux和Linux之间、Linux和Windows之间的samba服务。
地址规划
OSIPrehl9.0192.168.96.171OpenEuler192.168.96.251windowserver2016192.168.96.248 准备工作

rehl9.0

1、配置yum堆栈
# cat /etc/yum.repos.d/dvd.repo

name=BaseOS
baseurl=file:///mnt/cdrom/BaseOS
enabled=1
gpgcheck=0

name=AppStream
baseurl=file:///mnt/cdrom/AppStream
enabled=1
gpgcheck=0

验证
# 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服务端软件包
# dnf install samba*

验证
# 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客户端软件包
# dnf install samba-client cifs-utils -y
samba-client: 提供samba服务
cifs-utils: 提供文件共享服务

正式工作

rhel9.0

修改samba配置文件/etc/samba/smb.conf
原配置文件

      workgroup = WORKGROUP   #工作组名称,注意如果要与windows相通,工作组名称要一致
      security = user      #安全验证方式,默认即可
      passdb backend = tdbsam

      printing = cups
      printcap name = cups
      load printers = yes
      cups options = raw

      include = /etc/samba/usershares.conf

      comment = Home Directories
      valid users = %S, %D%w%S
      browseable = No
      read only = No
      inherit acls = Yes


      comment = All Printers
      path = /var/tmp
      printable = Yes
      create mask = 0600
      browseable = No


      comment = Printer Drivers
      path = /var/lib/samba/drivers
      write list = @printadmin root
      force group = @printadmin
      create mask = 0664
      directory mask = 0775

workgroup

在windows主机上,查看
https://i-blog.csdnimg.cn/direct/1aeaa98937484261879af908b663cad5.png
有大概你的配置文件里面是SAMBA工作组名
添加此条目进配置文件

      comment =public      #描述信息
      path= /share         #要共享出去的目录
      writable= yes          #允许读写
      read only = no         #关闭只读
      browseable = yes       #信息网络可见
      valid users = samba01#审核访问用户

在文件中,我们规划了要共享的目次,要创建的用户,现在将其创建出来
# mkdir /share
# useradd samba01
# echo redhat| passwd --stdin samba01
Changing password for user samba01.
passwd: all authentication tokens updated successfully.
# smbpasswd -a samba01
New SMB password:
Retype new SMB password:
Added user samba01.


注意,在你添加samba账号的时间,最好暗码和samba用户保持一致
修改samba目次权限,包管共享出去的时间可以正常使用
# echo redhat >/share/file.txt
# chmod 777 -R /share/
# chown samba01:samba01 -R /share/file.txt

关闭防火墙大概放行服务

关闭
# systemctl stop firewalld
# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

放行
# firewall-cmd --add-service=samba --permanent
success
# firewall-cmd --reload
success

关闭Selinux,大概修改文件标签

关闭
# setenforce 0


修改标签
# chcon -t samba_share_t /share/file.txt-R

重启samba服务

# systemctl restart smb
# systemctl enable smb
Created symlink /etc/systemd/system/multi-user.target.wants/smb.service → /usr/lib/systemd/system/smb.service.


OpenEuler

列出目标主机的共享目次

# 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

以命令行共享访问

# smbclient //192.168.96.171/public-U samba01%redhat
Try "help" to get a list of possible commands.
smb: \> ls
.                                 D      0Fri Sep 27 12:49:12 2024
..                                  D      0Fri Sep 27 12:44:33 2024
file.txt                            N      7Fri Sep 27 12:49:12 2024

                100101372 blocks of size 1024. 94965448 blocks available

在当前主机上挂载该目次

# mkdir /mnt/smbshare
# mount -t cifs //192.168.96.171/public/mnt/smbshare-o username=samba01
页: [1]
查看完整版本: 配置和管理samba服务器