1. 程式人生 > >samba服務(2)

samba服務(2)

samba服務器 默認 linux info 安裝 oba 掛載點 http centos

技術分享圖片

實現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)