Linux:SAMBA

安装SAMBA服务

# 用yum安装SAMBA服务
[root@localhost ~]# yum install samba -y
正在更新 Subscription Management 软件仓库。
无法读取客户身份

本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。

上次元数据过期检查:0:56:49 前,执行于 2024年05月11日 星期六 15时45分59秒。
依赖关系解决。
=========================================================================================================
 软件包                           架构             版本                       仓库                  大小
=========================================================================================================
安装:
 samba                            x86_64           4.19.4-104.el9             ali_baseos           989 k
升级:
 libldb                           x86_64           2.8.0-1.el9                ali_baseos           190 k
 libsmbclient                     x86_64           4.19.4-104.el9             ali_baseos            74 k
 libtalloc                        x86_64           2.4.1-1.el9                ali_baseos            31 k
 libtdb                           x86_64           1.4.9-1.el9                ali_baseos            51 k
 libtevent                        x86_64           0.16.0-1.el9               ali_baseos            48 k
 libwbclient                      x86_64           4.19.4-104.el9             ali_baseos            44 k
 samba-client-libs                x86_64           4.19.4-104.el9             ali_baseos           5.1 M
 samba-common                     noarch           4.19.4-104.el9             ali_baseos           149 k
 samba-common-libs                x86_64           4.19.4-104.el9             ali_baseos           101 k
安装依赖关系:
 libnetapi                        x86_64           4.19.4-104.el9             ali_baseos           143 k
 samba-common-tools               x86_64           4.19.4-104.el9             ali_baseos           471 k
 samba-dcerpc                     x86_64           4.19.4-104.el9             ali_baseos           685 k
 samba-ldb-ldap-modules           x86_64           4.19.4-104.el9             ali_baseos            28 k
 samba-libs                       x86_64           4.19.4-104.el9             ali_baseos           126 k

事务概要
=========================================================================================================
安装  6 软件包
升级  9 软件包

总下载:8.1 M
下载软件包:
(1/15): libnetapi-4.19.4-104.el9.x86_64.rpm                              408 kB/s | 143 kB     00:00    
(2/15): samba-common-tools-4.19.4-104.el9.x86_64.rpm                     1.0 MB/s | 471 kB     00:00    
(3/15): samba-ldb-ldap-modules-4.19.4-104.el9.x86_64.rpm                 327 kB/s |  28 kB     00:00    
(4/15): samba-4.19.4-104.el9.x86_64.rpm                                  1.6 MB/s | 989 kB     00:00    
(5/15): samba-libs-4.19.4-104.el9.x86_64.rpm                             831 kB/s | 126 kB     00:00    
(6/15): samba-dcerpc-4.19.4-104.el9.x86_64.rpm                           1.8 MB/s | 685 kB     00:00    
(7/15): libldb-2.8.0-1.el9.x86_64.rpm                                    1.8 MB/s | 190 kB     00:00    
(8/15): libsmbclient-4.19.4-104.el9.x86_64.rpm                           968 kB/s |  74 kB     00:00    
(9/15): libtalloc-2.4.1-1.el9.x86_64.rpm                                 354 kB/s |  31 kB     00:00    
(10/15): libtdb-1.4.9-1.el9.x86_64.rpm                                   480 kB/s |  51 kB     00:00    
(11/15): libtevent-0.16.0-1.el9.x86_64.rpm                               658 kB/s |  48 kB     00:00    
(12/15): libwbclient-4.19.4-104.el9.x86_64.rpm                           374 kB/s |  44 kB     00:00    
(13/15): samba-common-4.19.4-104.el9.noarch.rpm                          1.4 MB/s | 149 kB     00:00    
(14/15): samba-common-libs-4.19.4-104.el9.x86_64.rpm                     1.4 MB/s | 101 kB     00:00    
(15/15): samba-client-libs-4.19.4-104.el9.x86_64.rpm                     2.9 MB/s | 5.1 MB     00:01    
---------------------------------------------------------------------------------------------------------
总计                                                                     3.2 MB/s | 8.1 MB     00:02     
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                          1/1 
  升级    : libtalloc-2.4.1-1.el9.x86_64                                                            1/24 
  升级    : libtevent-0.16.0-1.el9.x86_64                                                           2/24 
  升级    : libtdb-1.4.9-1.el9.x86_64                                                               3/24 
  运行脚本: samba-common-4.19.4-104.el9.noarch                                                      4/24 
  升级    : samba-common-4.19.4-104.el9.noarch                                                      4/24 
  运行脚本: samba-common-4.19.4-104.el9.noarch                                                      4/24 
  升级    : libldb-2.8.0-1.el9.x86_64                                                               5/24 
  运行脚本: libwbclient-4.19.4-104.el9.x86_64                                                       6/24 
  升级    : libwbclient-4.19.4-104.el9.x86_64                                                       6/24 
  升级    : samba-common-libs-4.19.4-104.el9.x86_64                                                 7/24 
  升级    : samba-client-libs-4.19.4-104.el9.x86_64                                                 8/24 
  安装    : libnetapi-4.19.4-104.el9.x86_64                                                         9/24 
  安装    : samba-libs-4.19.4-104.el9.x86_64                                                       10/24 
  安装    : samba-dcerpc-4.19.4-104.el9.x86_64                                                     11/24 
  安装    : samba-ldb-ldap-modules-4.19.4-104.el9.x86_64                                           12/24 
  安装    : samba-common-tools-4.19.4-104.el9.x86_64                                               13/24 
  安装    : samba-4.19.4-104.el9.x86_64                                                            14/24 
  运行脚本: samba-4.19.4-104.el9.x86_64                                                            14/24 
  升级    : libsmbclient-4.19.4-104.el9.x86_64                                                     15/24 
  清理    : libsmbclient-4.18.6-100.el9.x86_64                                                     16/24 
  清理    : samba-client-libs-4.18.6-100.el9.x86_64                                                17/24 
  清理    : samba-common-libs-4.18.6-100.el9.x86_64                                                18/24 
  清理    : libwbclient-4.18.6-100.el9.x86_64                                                      19/24 
  清理    : libldb-2.7.2-2.el9.x86_64                                                              20/24 
  清理    : samba-common-4.18.6-100.el9.noarch                                                     21/24 
  清理    : libtevent-0.14.1-2.el9.x86_64                                                          22/24 
  清理    : libtalloc-2.4.0-2.el9.x86_64                                                           23/24 
  清理    : libtdb-1.4.8-2.el9.x86_64                                                              24/24 
  运行脚本: libtdb-1.4.8-2.el9.x86_64                                                              24/24 
  验证    : libnetapi-4.19.4-104.el9.x86_64                                                         1/24 
  验证    : samba-4.19.4-104.el9.x86_64                                                             2/24 
  验证    : samba-common-tools-4.19.4-104.el9.x86_64                                                3/24 
  验证    : samba-dcerpc-4.19.4-104.el9.x86_64                                                      4/24 
  验证    : samba-ldb-ldap-modules-4.19.4-104.el9.x86_64                                            5/24 
  验证    : samba-libs-4.19.4-104.el9.x86_64                                                        6/24 
  验证    : libldb-2.8.0-1.el9.x86_64                                                               7/24 
  验证    : libldb-2.7.2-2.el9.x86_64                                                               8/24 
  验证    : libsmbclient-4.19.4-104.el9.x86_64                                                      9/24 
  验证    : libsmbclient-4.18.6-100.el9.x86_64                                                     10/24 
  验证    : libtalloc-2.4.1-1.el9.x86_64                                                           11/24 
  验证    : libtalloc-2.4.0-2.el9.x86_64                                                           12/24 
  验证    : libtdb-1.4.9-1.el9.x86_64                                                              13/24 
  验证    : libtdb-1.4.8-2.el9.x86_64                                                              14/24 
  验证    : libtevent-0.16.0-1.el9.x86_64                                                          15/24 
  验证    : libtevent-0.14.1-2.el9.x86_64                                                          16/24 
  验证    : libwbclient-4.19.4-104.el9.x86_64                                                      17/24 
  验证    : libwbclient-4.18.6-100.el9.x86_64                                                      18/24 
  验证    : samba-client-libs-4.19.4-104.el9.x86_64                                                19/24 
  验证    : samba-client-libs-4.18.6-100.el9.x86_64                                                20/24 
  验证    : samba-common-4.19.4-104.el9.noarch                                                     21/24 
  验证    : samba-common-4.18.6-100.el9.noarch                                                     22/24 
  验证    : samba-common-libs-4.19.4-104.el9.x86_64                                                23/24 
  验证    : samba-common-libs-4.18.6-100.el9.x86_64                                                24/24 
已更新安装的产品。

已升级:
  libldb-2.8.0-1.el9.x86_64                             libsmbclient-4.19.4-104.el9.x86_64              
  libtalloc-2.4.1-1.el9.x86_64                          libtdb-1.4.9-1.el9.x86_64                       
  libtevent-0.16.0-1.el9.x86_64                         libwbclient-4.19.4-104.el9.x86_64               
  samba-client-libs-4.19.4-104.el9.x86_64               samba-common-4.19.4-104.el9.noarch              
  samba-common-libs-4.19.4-104.el9.x86_64              
已安装:
  libnetapi-4.19.4-104.el9.x86_64                          samba-4.19.4-104.el9.x86_64                   
  samba-common-tools-4.19.4-104.el9.x86_64                 samba-dcerpc-4.19.4-104.el9.x86_64            
  samba-ldb-ldap-modules-4.19.4-104.el9.x86_64             samba-libs-4.19.4-104.el9.x86_64              

完毕!

如果提示无法安装可以尝试替换yum源

验证是否安装成功

[root@localhost ~]# rpm -qa | grep -i samba
samba-common-4.19.4-104.el9.noarch
samba-common-libs-4.19.4-104.el9.x86_64
samba-client-libs-4.19.4-104.el9.x86_64
samba-libs-4.19.4-104.el9.x86_64
samba-dcerpc-4.19.4-104.el9.x86_64
samba-ldb-ldap-modules-4.19.4-104.el9.x86_64
samba-common-tools-4.19.4-104.el9.x86_64
samba-4.19.4-104.el9.x86_64

关闭防火墙(可能需要)

# 关闭防火墙
[root@localhost ~]# systemctl stop firewalld

# 验证防火墙是否关闭  Active: inactive (dead)即为关闭
[root@localhost ~]# systemctl status firewalld
○ firewalld.service - firewalld - dynamic firewall daemon
     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; preset: enabled)
     Active: inactive (dead) since Sat 2024-05-11 17:16:12 CST; 34s ago
   Duration: 51min 17.965s
       Docs: man:firewalld(1)
    Process: 40782 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0>
   Main PID: 40782 (code=exited, status=0/SUCCESS)
        CPU: 528ms

5月 11 16:24:53 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
5月 11 16:24:54 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
5月 11 17:16:12 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
5月 11 17:16:12 localhost.localdomain systemd[1]: firewalld.service: Deactivated successfully.
5月 11 17:16:12 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.

启动SAMBA服务

# 启动samba服务
[root@localhost ~]# systemctl start smb

# 设置开机启动
[root@localhost ~]# systemctl enable smb
Created symlink /etc/systemd/system/multi-user.target.wants/smb.service → /usr/lib/systemd/system/smb.service.

# 检查samba服务运行状态
[root@localhost ~]# systemctl status smb
● smb.service - Samba SMB Daemon
     Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; preset: disabled)
     Active: active (running) since Sat 2024-05-11 16:46:25 CST; 9s ago
       Docs: man:smbd(8)
             man:samba(7)
             man:smb.conf(5)
   Main PID: 41435 (smbd)
     Status: "smbd: ready to serve connections..."
      Tasks: 3 (limit: 10684)
     Memory: 10.9M
        CPU: 66ms
     CGroup: /system.slice/smb.service
             ├─41435 /usr/sbin/smbd --foreground --no-process-group
             ├─41437 /usr/sbin/smbd --foreground --no-process-group
             └─41438 /usr/sbin/smbd --foreground --no-process-group

5月 11 16:46:25 localhost.localdomain systemd[1]: Starting Samba SMB Daemon...
5月 11 16:46:25 localhost.localdomain smbd[41435]: [2024/05/11 16:46:25.882226,  0] ../../source3/smbd/s>
5月 11 16:46:25 localhost.localdomain smbd[41435]:   smbd version 4.19.4 started.
5月 11 16:46:25 localhost.localdomain smbd[41435]:   Copyright Andrew Tridgell and the Samba Team 1992-2>
5月 11 16:46:25 localhost.localdomain systemd[1]: Started Samba SMB Daemon.

配置SAMBA服务的配置文件

vim /etc/samba/smb.conf

在其底部增加

[test]
        comment = file
        path = /home/test
        writable = yes

测试Samba的设置是否正确无误

# 显示ok即可
[root@localhost ~]# testparm
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Weak crypto is allowed by GnuTLS (e.g. NTLM as a compatibility fallback)

Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions
 
# Global parameters
[global]
        printcap name = cups
        security = USER
        workgroup = SAMBA
        idmap config * : backend = tdb
        cups options = raw


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


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


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


[test]
        comment = file
        path = /home/test
        writable = yes

确保设置的目录存在且有权限

# 创建指定目录
[root@localhost ~]# mkdir /home/test

# 给予目录所有权限
[root@localhost ~]# chmod 777 /home/test

创建访问用户

# 创建testuser用户
[root@localhost ~]# useradd testuser

# 将创建的用户添加进Samba,并设置密码
[root@localhost ~]# smbpasswd -a testuser
New SMB password:
Retype new SMB password:
Added user testuser.

安装samba客户端测试连接

# 使用yum安装
[root@localhost ~]# yum install samba-client -y
正在更新 Subscription Management 软件仓库。
无法读取客户身份

本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。

上次元数据过期检查:0:43:14 前,执行于 2024年05月11日 星期六 16时28分30秒。
依赖关系解决。
=========================================================================================================
 软件包                       架构              版本                      仓库                      大小
=========================================================================================================
安装:
 samba-client                 x86_64            4.19.4-104.el9            ali_appstream            691 k
升级:
 libldb                       x86_64            2.8.0-1.el9               ali_baseos               190 k
 libsmbclient                 x86_64            4.19.4-104.el9            ali_baseos                74 k
 libtalloc                    x86_64            2.4.1-1.el9               ali_baseos                31 k
 libtdb                       x86_64            1.4.9-1.el9               ali_baseos                51 k
 libtevent                    x86_64            0.16.0-1.el9              ali_baseos                48 k
 libwbclient                  x86_64            4.19.4-104.el9            ali_baseos                44 k
 samba-client-libs            x86_64            4.19.4-104.el9            ali_baseos               5.1 M
 samba-common                 noarch            4.19.4-104.el9            ali_baseos               149 k
 samba-common-libs            x86_64            4.19.4-104.el9            ali_baseos               101 k

事务概要
=========================================================================================================
安装  1 软件包
升级  9 软件包

总下载:6.4 M
下载软件包:
(1/10): libsmbclient-4.19.4-104.el9.x86_64.rpm                           450 kB/s |  74 kB     00:00    
(2/10): libldb-2.8.0-1.el9.x86_64.rpm                                    800 kB/s | 190 kB     00:00    
(3/10): libtalloc-2.4.1-1.el9.x86_64.rpm                                 355 kB/s |  31 kB     00:00    
(4/10): libtdb-1.4.9-1.el9.x86_64.rpm                                    638 kB/s |  51 kB     00:00    
(5/10): libtevent-0.16.0-1.el9.x86_64.rpm                                999 kB/s |  48 kB     00:00    
(6/10): libwbclient-4.19.4-104.el9.x86_64.rpm                            1.3 MB/s |  44 kB     00:00    
(7/10): samba-common-4.19.4-104.el9.noarch.rpm                           2.1 MB/s | 149 kB     00:00    
(8/10): samba-client-4.19.4-104.el9.x86_64.rpm                           1.6 MB/s | 691 kB     00:00    
(9/10): samba-common-libs-4.19.4-104.el9.x86_64.rpm                      1.7 MB/s | 101 kB     00:00    
(10/10): samba-client-libs-4.19.4-104.el9.x86_64.rpm                     4.6 MB/s | 5.1 MB     00:01    
---------------------------------------------------------------------------------------------------------
总计                                                                     4.5 MB/s | 6.4 MB     00:01     
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                          1/1 
  升级    : libtalloc-2.4.1-1.el9.x86_64                                                            1/19 
  升级    : libtevent-0.16.0-1.el9.x86_64                                                           2/19 
  运行脚本: samba-common-4.19.4-104.el9.noarch                                                      3/19 
  升级    : samba-common-4.19.4-104.el9.noarch                                                      3/19 
  运行脚本: samba-common-4.19.4-104.el9.noarch                                                      3/19 
  升级    : libtdb-1.4.9-1.el9.x86_64                                                               4/19 
  升级    : libldb-2.8.0-1.el9.x86_64                                                               5/19 
  运行脚本: libwbclient-4.19.4-104.el9.x86_64                                                       6/19 
  升级    : libwbclient-4.19.4-104.el9.x86_64                                                       6/19 
  升级    : samba-common-libs-4.19.4-104.el9.x86_64                                                 7/19 
  升级    : samba-client-libs-4.19.4-104.el9.x86_64                                                 8/19 
  升级    : libsmbclient-4.19.4-104.el9.x86_64                                                      9/19 
  安装    : samba-client-4.19.4-104.el9.x86_64                                                     10/19 
  运行脚本: samba-client-4.19.4-104.el9.x86_64                                                     10/19 
  清理    : libsmbclient-4.18.6-100.el9.x86_64                                                     11/19 
  清理    : samba-client-libs-4.18.6-100.el9.x86_64                                                12/19 
  清理    : samba-common-libs-4.18.6-100.el9.x86_64                                                13/19 
  清理    : libwbclient-4.18.6-100.el9.x86_64                                                      14/19 
  清理    : libldb-2.7.2-2.el9.x86_64                                                              15/19 
  清理    : samba-common-4.18.6-100.el9.noarch                                                     16/19 
  清理    : libtevent-0.14.1-2.el9.x86_64                                                          17/19 
  清理    : libtalloc-2.4.0-2.el9.x86_64                                                           18/19 
  清理    : libtdb-1.4.8-2.el9.x86_64                                                              19/19 
  运行脚本: libtdb-1.4.8-2.el9.x86_64                                                              19/19 
  验证    : samba-client-4.19.4-104.el9.x86_64                                                      1/19 
  验证    : libldb-2.8.0-1.el9.x86_64                                                               2/19 
  验证    : libldb-2.7.2-2.el9.x86_64                                                               3/19 
  验证    : libsmbclient-4.19.4-104.el9.x86_64                                                      4/19 
  验证    : libsmbclient-4.18.6-100.el9.x86_64                                                      5/19 
  验证    : libtalloc-2.4.1-1.el9.x86_64                                                            6/19 
  验证    : libtalloc-2.4.0-2.el9.x86_64                                                            7/19 
  验证    : libtdb-1.4.9-1.el9.x86_64                                                               8/19 
  验证    : libtdb-1.4.8-2.el9.x86_64                                                               9/19 
  验证    : libtevent-0.16.0-1.el9.x86_64                                                          10/19 
  验证    : libtevent-0.14.1-2.el9.x86_64                                                          11/19 
  验证    : libwbclient-4.19.4-104.el9.x86_64                                                      12/19 
  验证    : libwbclient-4.18.6-100.el9.x86_64                                                      13/19 
  验证    : samba-client-libs-4.19.4-104.el9.x86_64                                                14/19 
  验证    : samba-client-libs-4.18.6-100.el9.x86_64                                                15/19 
  验证    : samba-common-4.19.4-104.el9.noarch                                                     16/19 
  验证    : samba-common-4.18.6-100.el9.noarch                                                     17/19 
  验证    : samba-common-libs-4.19.4-104.el9.x86_64                                                18/19 
  验证    : samba-common-libs-4.18.6-100.el9.x86_64                                                19/19 
已更新安装的产品。

已升级:
  libldb-2.8.0-1.el9.x86_64                             libsmbclient-4.19.4-104.el9.x86_64              
  libtalloc-2.4.1-1.el9.x86_64                          libtdb-1.4.9-1.el9.x86_64                       
  libtevent-0.16.0-1.el9.x86_64                         libwbclient-4.19.4-104.el9.x86_64               
  samba-client-libs-4.19.4-104.el9.x86_64               samba-common-4.19.4-104.el9.noarch              
  samba-common-libs-4.19.4-104.el9.x86_64              
已安装:
  samba-client-4.19.4-104.el9.x86_64                                                                     

完毕!

# 测试是否安装成功
[root@localhost ~]# rpm -qa | grep -i samba-client
samba-client-libs-4.19.4-104.el9.x86_64
samba-client-4.19.4-104.el9.x86_64

连接samba服务

指令:smbclient -U 用户名 //ip/路径

# 连接samba
[root@localhost ~]# smbclient -U testuser //192.168.22.131/test
Password for [SAMBA\testuser]:
Try "help" to get a list of possible commands.
smb: \> 

smbclient的详细语法

温馨提示:本文最后更新于2024-09-29 09:13:29,某些文章具有时效性,若有错误或已失效,请在下方留言或联系站长
© 版权声明
THE END
喜欢就支持一下吧
点赞1 分享
相关推荐
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情

    暂无评论内容