配置samba共享,实现/www目录共享

发布时间 2023-10-07 15:14:03作者: 小糊涂90


#服务器端配置:
[root@samba ~]#yum install -y samba
[root@samba ~]#groupadd -r www
[root@samba ~]#useradd -s /sbin/nologin -G www test1
[root@samba ~]#smbpasswd -a test1
New SMB password:
Retype new SMB password:
Added user test1.
[root@samba ~]#useradd -s /sbin/nologin test2
[root@samba ~]#smbpasswd -a test2
New SMB password:
Retype new SMB password:
Added user test2.
[root@samba ~]#mkdir /www
[root@samba ~]#chgrp www /www
[root@samba ~]#chmod 2775 /www
[root@samba ~]#vim /etc/samba/smb.conf
#加上一下这段配置。设置共享目录为/www,设置www组中用户有写权限
[share]
path = /www
write list = @www

#启动服务
[root@samba ~]#systemctl enable --now smb nmb

#客户端配置
[root@client ~]# yum install -y cifs-utils
#分别用test1,test2用户进行挂载共享目录
[root@client ~]# mkdir /mnt/test1
[root@client ~]# mkdir /mnt/test2
[root@client ~]# mount -o username=test1 //10.0.0.150/share /mnt/test1
Password for test1@//10.0.0.150/share: ******
[root@client ~]# mount -o username=test2 //10.0.0.150/share /mnt/test2
Password for test2@//10.0.0.150/share: ******
[root@client ~]# echo "test1" >> /mnt/test1/test.txt
[root@client ~]# cat /mnt/test1/test.txt
test1
[root@client ~]# touch /mnt/test2/test.txt
touch: cannot touch ‘/mnt/test2/test.txt’: Permission denied
#说明:test1用户在www组,samba服务给了www组写的权限,test2用户不在www组,因此创建文件失败。

#配置自动挂载
[root@client ~]# cat /etc/smb.txt
username=test1
password=123456
[root@client ~]# chmod 600 /etc/smb.txt
[root@client ~]# echo "//10.0.0.150/share /mnt/test1 cifs credentials=/etc/smb.txt 0 0" >> /etc/fstab
#自动挂载测试ok
[root@client ~]# mount -a
[root@client ~]# ll /mnt/test1
total 4
-rwxr-xr-x 1 root root 6 Nov 18 18:40 test.txt

[root@client ~]# yum install -y samba-client
[root@client ~]# smbclient //10.0.0.150/share -U test1%123456
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Thu Nov 18 18:40:54 2021
.. D 0 Thu Nov 18 18:29:35 2021
test.txt A 6 Thu Nov 18 18:40:54 2021

104806400 blocks of size 1024. 98400288 blocks available
smb: \>