在Ubuntu上安装Samba

首先更新apt软件包索引:

sudo apt update

使用以下命令安装Samba软件包以下命令:

sudo apt install -y samba samba-common

安装完成后,Samba服务将自动启动。要检查Samba服务器是否正在运行,请键入:

sudo systemctl status smbd

输出应如下所示,表明Samba服务处于活动状态并正在运行:

● nmbd.service - Samba NMB Daemon
Loaded: loaded (/lib/systemd/system/nmbd.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2019-01-27 02:36:20 PST; 4s ago
    Docs: man:nmbd(8)
        man:samba(7)
        man:smb.conf(5)
Main PID: 4262 (nmbd)
Status: "nmbd: ready to serve connections..."
    Tasks: 1 (limit: 2319)
CGroup: /system.slice/nmbd.service
        `-4262 /usr/sbin/nmbd --foreground --no-process-group

添加samba到自启服务:

sudo systemctl enable smbd

至此,已经安装了Samba并准备对其进行配置。

配置全局Samba选项

编辑samba配置文件:

sudo vi /etc/samba/smb.conf

Samba软件包随附的默认配置文件是为独立的Samba服务器配置的。打开文件并确保将server role设置为standalone server

...
# Most people will want "standalone sever" or "member server".
# Running as "active directory domain controller" will require first
# running "samba-tool domain provision" to wipe databases and create a
# new domain.
   server role = standalone server
...

默认情况下,Samba监听所有接口。如果您只想从内部网络限制对Samba服务器的访问,请取消注释以下两行并指定要绑定到的接口:

...
# The specific set of interfaces / networks to bind to
# This can be either the interface name or an IP address/netmask;
# interface names are normally preferred
interfaces = 127.0.0.0/8 eth0

# Only bind to the named interfaces and/or networks; you must use the
# 'interfaces' option above to use this.
# It is recommended that you enable this feature if your Samba machine is
# not protected by a firewall or is a firewall itself.  However, this
# option cannot handle dynamic or non-broadcast interfaces correctly.
bind interfaces only = yes
...

完成后,运行testparm实用程序以检查Samba配置文件中是否有错误。如果没有语法错误,您将看到Loaded services file OK.

重新启动Samba服务:

sudo systemctl restart smbd

配置Samba共享

打开Samba配置文件,并添加以下部分:

[users]
    path = /samba/users
    browseable = yes
    read only = no
    force create mode = 0660
    force directory mode = 2770
    valid users = @sambashare @sadmin

[josh]
    path = /samba/josh
    browseable = no
    read only = no
    force create mode = 0660
    force directory mode = 2770
    valid users = josh @sadmin

● [users]和[josh]-登录时将使用的共享名称。(按照喜好设置)
● path -分享的路径。(分享的绝对路径)
● browseable -是否应在可用共享列表中列出该共享。通过设置为no,其他用户将看不到共享。
● read only -valid users列表中指定的用户是否能够写入此共享。
● force create mode -设置此共享中新创建文件的权限。
● force directory mode -设置此共享中新创建目录的权限。
● valid users -允许访问共享的用户和组的列表。群组以@符号为前缀。

● invalid users-设定只有此名单内的用户不能访问共享资源(拒绝优先)(用户名/@组名)
● public--是yes/否no公开共享,若为否则进行身份验证(只有当security = share 时此项才起作用)
● guest ok--是yes/否no公开共享,若为否则进行身份验证(只有当security = share 时此项才起作用)
● write list-若设定为只读时,则只有此设定的名单内的成员才可作写入动作(用户名/@组名)
● create mask-建立文件时所给的权限
● directory mask-建立目录时所给的权限

完成后,使用以下方法重新启动Samba服务:

sudo service smbd restart
Last modification:May 6th, 2022 at 02:24 am
如果觉得我的文章对你有用,请随意赞赏