配置samba共享 一个用户有权限 多个用户可以借此用户访问

  • Samba :
    - 用途:为客户机提供共享使用的文件夹
    - 协议: SMB(TCP 139) , CIFS( TCP 445)

服务端:

防火墙设置为trusted

 [root@server0 ~]#  firewall-cmd --set-default-zone=trusted

创建samba用户:

[root@server0 ~]# useradd harry
[root@server0 ~]# pdbedit -a harry
new password:
retype new password:

服务器要装samba 起服务

[root@server0 ~]# yum -y install samba
[root@server0 ~]# systemctl restart smb
[root@server0 ~]# systemctl enable smb

创建共享目录

[root@server0 ~]#  mkdir /common
[root@server0 ~]# touch 1234 > /common/1.txt

修改配置文件

[root@server0 ~]# vim /etc/samba/smb.conf
.. .. 
[common]                    //共享目录
path = /common              //实际路径
write list = harry     
.. ..


[root@server0 ~]#systemctl restart smb
[root@server0 ~]#systemctl enable smb

开启SELinux 读写权限

[root@server0 ~]# getsebool -a | grep samba       //查找关于samba的权限
[root@server0 ~]# setsebool -P samba_export_all_rw on    //开启永久读写权限

单独为用户设置ACL权限

[root@server0 ~]#setfacl -m u:harry:rwx /common

客户端:

防火墙设置为trusted

 [root@server0 ~]#  firewall-cmd --set-default-zone=trusted

安装客户端:

[root@desktop0 ~]# yum -y install samba-client 
[root@desktop0 ~]# yum -y install cifs-utils

创建目录:

[root@desktop0 ~]# mkdir /mnt/nsd11

查看共享 修改配置文件

[root@desktop0 ~]#  smbclient -L 172.25.0.11       //查看共享名
[root@desktop0 ~]#  smbclient -U harry //172.25.0.11/common      //查看共享内容


[root@desktop0 ~]# vim /etc/fstab
.. ..
//172.25.0.11/common /mnt/nsd11 cifs username=harry,password=123456,multiuser,sec=ntlmssp,_netdev 0 0


[root@desktop0 ~]# mount -a
[root@desktop0 ~]# df -h

在客户端任何用户 都可借助harry 对/mnt/nsd11 读取写入


[root@desktop0 ~]# su - student      //任何用户都可以
[student@desktop0 ~]$ cifscreds -u harry add 172.25.0.11    //借harry 之名 读取写入信息
Password: 
[student@desktop0 ~]$ ls  /mnt/nsd11
1.txt  
[student@desktop0 ~]$ touch /mnt/nsd11/2.txt
[student@desktop0 ~]$ls
1.txt 2.txt

服务端:


[root@server0 ~]# ll /common
总用量 2
-rw-r--r--. 1 root root 5 52 12:52 1.txt
-rw-r--r--. 1 harry harry 0 52 14:07 2.txt   //属主属组 都是harry

你可能感兴趣的:(配置samba共享 一个用户有权限 多个用户可以借此用户访问)