准备两台虚拟机,server1.example.com(samba服务器),server2.example.com(客户端)
1、samba服务
在主机Server1上配置Samba服务。
您的Samba服务器必须是STAFF工作组的一个成员。
共享/common目录,共享名为common。
只有example.com域内的客户端可以访问common共享。
common共享必须是可以浏览的。
用户marry必须能够读取共享中的内容,如果需要的话,验证密 码是:redhat
2、多用户Samba挂载
在主机Server1上通过Samba共享目录/storage。
共享名为share。
共享目录share必须可以浏览。
用户jim能以读的方式访问此共享,访问密码为redhat。
用户bob能以读写的方式访问此共享,访问密码是redhat。
此共享永久挂载在desktop30上的/mnt/smb目录,并使用用户jim进行认证,任何用户可临时通过bob来获得读写权限。
1.samba服务
在主机Server30上配置Samba服务。
您的Samba服务器必须是STAFF工作组的一个成员。
共享/common目录,共享名为common。
只有example.com域内的客户端可以访问common共享。
common共享必须是可以浏览的。
用户marry必须能够读取共享中的内容,如果需要的话,验证密 码是:redhat
[root@server1 samba]# useradd -s /sbin/nologin marry //添加用户,不允许ssh登录系统
[root@server1 samba]# smbpasswd -a marry //写入密码,redhat
New SMB password:
Retype new SMB password:
Added user marry.
[root@server1 samba]# mkdir /common //创建common目录
[root@server1 samba]# setfacl -m u:marry:r-x /common //设置权限,保证samba用户的访问权限和服务设置的权限一致
[root@server1 samba]# pdbedit -L //查看samba上面的用户
marry:1001:
[root@server1 samba]# vim smb.conf //配置文件,在/etc/samba下的sam.conf文件
[common]
path = /common //共享目录的绝对路径
browseable = yes //共享不可以浏览
valid user = marry //定义可访问的用户
writable = no //可写权限
[root@server1 samba]# vim smb.conf.example //主配置模板文件
workgroup = STAFF //工作组
; hosts allow = 127. 192.168.12. 192.168.13. 192.168.35 //添加当前主机网段,允许只有example.com(192.168.35)域内的客户端可以访问common共享
[root@server1 samba]# systemctl restart smb.service //重启服务
[root@server1 samba]# systemctl enable smb.service //重启服务
[root@server1 samba]# systemctl restart nmb.service //重启服务
[root@server1 samba]# systemctl enable nmb.service //重启服务
//在server2客户端进行测试
[root@server2 ~]# smbclient //192.168.35.142/common -U marry
Password for [SAMBA\marry]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Fri Jul 19 17:03:29 2024
.. D 0 Fri Jul 19 17:03:29 2024
2. 多用户Samba挂载
在主机Server1上通过Samba共享目录/storage。
共享名为share。
共享目录share必须可以浏览。
用户jim能以读的方式访问此共享,访问密码为redhat。
用户bob能以读写的方式访问此共享,访问密码是redhat。
此共享永久挂载在desktop30上的/mnt/smb目录,并使用用户jim进行认证,任何用户可临时通过bob来获得读写权限。
[root@server1 samba]# mkdir /storage //创建共享目录/storage
[root@server1 samba]# useradd -s /sbin/nologin bob
[root@server1 samba]# useradd -s /sbin/nologin jim
[root@server1 samba]# smbpasswd -a bob //写入密码,redhat
New SMB password:
Retype new SMB password:
Added user bob.
[root@server1 samba]# smbpasswd -a jim //写入密码,redhat
New SMB password:
Retype new SMB password:
Added user jim.
[root@server1 samba]# setfacl -m u:jim:r-x /storage/ //设置权限,保证samba用户的访问权限和服务设置的权限一致
[root@server1 samba]# setfacl -m u:bob:rwx /storage/ //设置权限,保证samba用户的访问权限和服务设置的权限一致
[root@server1 samba]# pdbedit -L //查看samba上面的用户
marry:1001:
jim:1003:
bob:1002:
[root@server1 samba]# vim smb.conf
[share]
path = /storage //共享目录的绝对路径
browseable = yes //共享不可以浏览
valid user = bob,jim //定义可访问的用户
write list = bob //定义具体读写共享权限的用户列表
[root@server1 samba]# systemctl restart smb.service //重启服务
[root@server1 samba]# systemctl enable smb.service //重启服务
[root@server1 samba]# systemctl restart nmb.service //重启服务
[root@server1 samba]# systemctl enable nmb.service //重启服务
在server2客户端上进行测试
[root@server2 ~]# cd /mnt/ //进入mnt目录
[root@server2 mnt]# mkdir smb //创建挂载点
[root@server2 ~]# vim /etc/fstab //进行永久挂载
//192.168.35.142/share /mnt/smb cifs username=jim,password=redhat,sec=ntlmssp 0 0 //挂载参数
[root@server2 ~]# mount -a
mount: (hint) your fstab has been modified, but systemd still uses
the old version; use 'systemctl daemon-reload' to reload.
[root@server2 ~]# systemctl daemon-reload
[root@server2 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 777M 9.0M 768M 2% /run
/dev/sda3 xfs 50G 1.7G 49G 4% /
/dev/sda1 xfs 960M 187M 774M 20% /boot
tmpfs tmpfs 389M 0 389M 0% /run/user/0
//192.168.35.142/share cifs 50G 6.1G 44G 13% /mnt/smb
[root@server2 ~]# yum -y install cifscreds
[root@server2 ~]# su - lsy
Last login: Mon Jul 22 14:09:12 CST 2024 on pts/0
[lsy@server2 ~]$ cifscreds add 192.168.35.142 -u bob //实现其对share共享具有bob的读写权限
Password: