码迷,mamicode.com
首页 > 其他好文 > 详细

samba服务(2)

时间:2018-06-28 15:22:32      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:art   lob   chcon   linu   margin   oba   gpo   comm   /etc   

技术分享图片

 

实现SAMBA共享

? 1)安装

yum install samba -y

? 2)创建samba用户和组

groupadd -r admins
useradd -s /sbin/nologin -G admins user1
smbpasswd -a user1
useradd -s /sbin/nologin -G admins user2
smbpasswd -a user2

? 3)创建samba共享目录,并设置SElinux

mkdir /data/share
chgrp admins /data/share
chmod 2775 /data/share
semanage fcontext -a -t samba_share_t /data/share(/.*)?
restorecon -vvFR /data/share/

? 4)samba服务器配置

vim /etc/samba/smb.conf
[global]
    security = user
    passdb backend = tdbsam
[share]
    comment = samba share dir
    path = /data/share
    write list = @admins
    browseable = Yes
systemctl start smb nmb
systemctl enable smb nmb
[root@centos7 ~]# firewall-cmd --permanent --add-service=samba
[root@centos7 ~]# firewall-cmd --reload

? 5)客户端测试

yum install samba-client -y
smbclient -L //192.168.0.7/ -U user1%user1
smbclient //192.168.0.7/share -U user1%user1
yum install cifs-utils -y
mount.cifs -o username=user1,password=user1 //192.168.0.7/share /mnt/smbdir/
vim /etc/fstab
//192.168.0.7/share /mnt/smbdir/ cifs credentials=/etc/smb.pass 0 0
# vim /etc/smb.pass
username=user1
password=user1
umount /mnt/smbdir/
mount -a
//192.168.0.7/share    7.0G   33M  7.0G   1% /mnt/smbdir

多用户挂载

? SAMBA共享默认只支持同时用一个用户挂载SMB共享,CentOS7中可启用多用户挂载功能,客户端挂载samba共享目录后,在客户端登录的不同用户访问同一个samba的挂载点,可获得不同权限。

? 1)服务器端配置:

yum install samba -y
mkdir /multiuser
vim /etc/samba/smb.conf
[share]
    path = /multiuser
    writable = no
    write list = @admins
groupadd -r admins
useradd -s /sbin/nologin -G admins user1
useradd -s /sbin/nologin user2
useradd -s /sbin/nologin user3
smbpasswd -a user1
smbpasswd -a user2
smbpasswd -a user3
chmod 777 /multiuser/
chcon -t samba_share_t /multiuser/
systemctl start smb
systemctl enable smb
touch /multiuser/testfile1

? 2)客户端挂载

yum install cifs-utils -y
vim /etc/fstab
//192.168.0.7/share /mnt cifs username=user1,password=user1,multiuser 0 0
mount -a
useradd user2; useradd user3
su - user2
$ cifscreds add -u user2 192.168.0.7
$ ls /mnt/

实现不同用户设置不同的共享目录和权限

vim /etc/samba/smb.conf
[global]
    workgroup = SAMBA
    security = user
    passdb backend = tdbsam
    log file = /var/log/samba/log.%I
    log level = 2
    config file = /etc/samba/conf.d/%U
mkdir /etc/samba/conf.d
vim /etc/samba/conf.d/user1
[share]
    comment = samba share dir
    path = /data/tools
    read only = yes
vim /etc/samba/conf.d/user2
[share]
    comment = samba share dir
    path = /data/src
    read only = no
mkdir /data/{tools,src}
chmod 777 /data/{tools,src}
smbclient //192.168.0.7/share -U user1%user1
smbclient //192.168.0.7/share -U user2%user2

 

 

samba服务(2)

标签:art   lob   chcon   linu   margin   oba   gpo   comm   /etc   

原文地址:https://www.cnblogs.com/Gmiaomiao/p/9238634.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!