第6步:配置Samba私有共享
只有批准组成员的用户才能使用密码访问私有文件夹。
首先为共享创建名为SMBGroup的Samba组。
只有成员可以访问。
要在Ubuntu中创建组,请运行下面的命令。
sudo addgroup smbgroup
将用户添加到组中
sudo usermod -aG smbgroup jack
将用户添加到Samba密码数据库。
sudo smbpasswd -a jack sudo smbpasswd -e jack
系统将提示用户输入并确认密码。
此密码将用于访问受保护的Samba共享。
创建受保护的目录:
sudo mkdir -p /samba/protected
只允许root和成员组访问此共享。
cd /samba/ sudo chown -R root:smbgroup protected sudo chmod -R 0770 protected
在smb.conf文件中共享该文件夹。
sudo nano /etc/samba/smb.conf
配置参考:
[Protected] path = /samba/protected valid users = @smbgroup guest ok = no writable = yes browsable = yes
保存更改。
重新启动Samba并测试更改。
sudo service smbd restart
测试环境
我们将使用192.168.1.0/24网络。
Windows机器:192.168.1.2
Linux机器:192.168.1.3
工作组名称:Workgroup
步骤2:将Ubuntu添加到Windows主机文件。
如果我们没有DNS系统,并且我们想按照他们的名称引用每个系统,则需要在每台计算机上的本地主机文件中添加名称。
对于Windows系统,打开hosts文件:
notepad C:\Windows\System32\drivers\etc\hosts
然后添加Ubuntu的信息条目:
192.168.1.3 ubuntu2004.localhost ubuntu2004
在Ubuntu机器上,添加Windows系统名称:
sudo nano /etc/hosts
同样添加windows的主机名信息
192.168.1.2 winjack
第5步:配置Samba共享
备份Samba默认配置文件。
sudo cp /etc/samba/smb.conf{,.backup}
打开Samba配置文件。
sudo nano /etc/samba/smb.conf
修改如下:
======================= Global Settings ======================= [global] ## Browsing/Identification ### # Change this to the workgroup/NT-domain name your Samba server will part of workgroup = WORKGROUP netbios name = ubuntu2004 security = user proxy = no map to guest = bad user #### Networking #### # 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. bind interfaces only = yes #Most people will want "standalone server" or "member server". #Running as "active directory domain controller" will require first server role = standalone server obey pam restrictions = yes #This boolean parameter controls whether Samba attempts to sync the Unix [public] path = /samba/public browseable = yes guest ok = yes guest only = yes read only = no force user = nobody force create mode = 0777 force directory mode = 0777
完成后,保存更改。
然后运行 testparm
实用程序检查Samba配置文件是否正确。
重新启动Samba服务。
sudo systemctl restart smbd
Samba是SMB/CIFS协议的开源实现,允许用户访问共享文件打印机和其他网络资源。
第6步:创建公共文件夹
public文件夹所有人都可以访问:
sudo mkdir -p /samba/public
设置权限,以便每个人都可以读取和写入。
sudo chown -R nobody:nogroup /samba/public sudo chmod -R 0775 /samba/public sudo chgrp sambashare /samba/public
重新启动Samba:
sudo service smbd restart
现在转到Windows机器,
打开Windows文件资源管理器以查看Ubuntu上的共享位置
\192.168.1.3\public
第4步:在Ubuntu上安装Samba
登录Ubuntu机器以安装Samba:
sudo apt update sudo apt install samba
查看Samba服务状态:
sudo systemctl status smbd
输出示例:
mbd.service - Samba SMB Daemon Loaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: > Active: active (running) since Wed 2016-05-06 18:23:55 CDT; 4min 27s ago Docs: man:smbd(8) man:samba(7) man:smb.conf(5) Process: 2026 ExecStartPre=/usr/share/samba/update-apparmor-samba-profile (> Main PID: 2039 (smbd) Status: "smbd: ready to serve connections. " Tasks: 4 (limit: 4657) Memory: 14.9M CGroup: /system.slice/smbd.service ├─2039 /usr/sbin/smbd --foreground --no-process-group
第3步:启用文件共享
要使文件共享可能,必须在Windows系统上启用该功能。
以管理员身份运行以下命令,启用文件搜索和网络发现。
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes netsh advfirewall firewall set rule group="Network Discovery" new enable=Yes
这样我们在Windows计算机上启用了文件共享。
第1步:识别Windows工作组
查看Windows机所属的工作组:
net config workstation
可以看到计算机的当前工作站域名,通常称为工作组。