如何在 CentOS 8 上安装 Samba

在本教程中,我们将向您展示如何在 CentOS 8 上安装 Samba。对于那些不知道的人,Samba 是免费的开源软件,可用于在 Linux 和视窗系统。

本文假设您至少具有 Linux 的基本知识,知道如何使用 shell,并且最重要的是,您在自己的 VPS 上托管您的站点。 安装非常简单,假设您在 root 帐户中运行,否则您可能需要添加 ‘sudo‘ 到获得 root 权限的命令。 我将向您展示如何在 CentOS 8 上逐步安装 Samba。

在 CentOS 8 上安装 Samba

步骤 1. 首先,让我们先确保您的系统是最新的。

sudo dnf update sudo dnf install epel-release

步骤 2. 在 CentOS 8 上安装 Samba。

现在我们运行以下命令来安装 Samba 及其依赖项:

sudo dnf install samba samba-common samba-client

安装完成后,启动 Sambe 服务,使其在系统启动时自动启动:

sudo systemctl start smb sudo systemctl status smb

步骤 3. Samba 配置。

首先,创建带有预配置设置和各种配置指令的默认 Samba 配置文件的备份副本:

cp /etc/samba/smb.conf /etc/samba/smb.conf.orig

接下来,创建一个名为 shared 的共享文件夹并分配必要的权限和所有权:

mkdir -p /srv/samba/idroot chmod -R 0777 /srv/samba/idroot chown -R nobody:nobody /srv/samba/idroot chcon -t samba_share_t /srv/samba/idroot

现在我们创建一个新的 samba 配置文件:

sudo nano /etc/samba/smb.conf

添加以下几行:

[global]         workgroup = WORKGROUP         netbios name = rhel         security = user ...[idroot] comment = Anonymous File Server Share         path = /srv/samba/idroot browsable =yes         writable = yes         guest ok = yes         read only = no         force user = nobody

Save 和 close 文件。 然后,重新启动 Samba 服务以应用更改:

sudo systemctl restart smb

要验证配置是否合理,请运行 testparm 命令:

testparm

输出:

Load smb config files from /etc/samba/smb.conf  rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (46384)  Unknown parameter encountered: "netbios"  Ignoring unknown parameter "netbios"  Processing section "[homes]"  Processing section "[printers]"  Processing section "[print$]"  Processing section "[idroot]"  Loaded services file OK.  Server role: ROLE_STANDALONE   Press enter to see a dump of your service definitions   # Global parameters  [global]         printcap name = cups         security = USER         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[idroot]        comment = Anonymous File Server Share         force user = nobody         guest ok = Yes         path = /srv/samba/idroot         read only = No

步骤 4. 配置防火墙。

我们必须打开相应的端口,以便其他机器可以访问 samba 共享资源:

sudo firewall-cmd --add-service=samba --zone=public --permanent sudo firewall-cmd --reload

步骤 5. 访问 Samba 共享路径。

要从 Windows 访问 samba 共享,请按 Windows 键 + R 启动运行对话框。 Enter IP 地址或主机名,然后按 Enter.

恭喜! 您已成功安装 Samba。 感谢您使用本教程在 CentOS 8 系统上安装 Samba。 如需更多帮助或有用信息,我们建议您查看 桑巴官方网站.