Samba - Server 配置
1. 安装所需软件
[root@s1 ~]# yum install samba -y
[root@s1 ~]# yum install samba-client -y
[root@s1 ~]# yum install policycoreutils-python
2. 创建共享目录
[root@s1 ~]# mkdir /sharedpath
[root@s1 ~]# semanage fcontext -a -t samba_share_t '/sharedpath(/.*)?'
[root@s1 ~]# restorecon -vvFR /sharedpath/
restorecon reset /sharedpath context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
3. 修改配置文件/etc/samba/smb.conf, 加上一行。
[myshare]
path = /sharedpath
4. 添加用户
[root@s1 ~]# useradd -s /sbin/nologin fred
[root@s1 ~]# smbpasswd -a fred
5. 启用Samba服务
[root@s1 ~]# systemctl start smb nmb
[root@s1 ~]# systemctl enable smb nmb
6. 添加防火墙规则
[root@s1 ~]# firewall-cmd --permanent --add-service=samba
[root@s1 ~]# firewall-cmd --reload
Samba - Client 配置
1. 安装所需软件
[root@r7-h1 ~]# yum install cifs-utils -y
2.创建挂载点
[root@r7-h1 ~]# mkdir /mnt/myshare
3.以fred身份挂载
[root@r7-h1 ~]# mount -o username=fred //192.168.122.243/myshare /mnt/myshare/
Password for fred@//192.168.122.243/myshare: ******
Multiuser
Server端
[root@s1 ~]# groupadd -r marketing
[root@s1 ~]# mkdir -p /smbshare
[root@s1 ~]# chgrp marketing /smbshare/
[root@s1 ~]# chmod 2775 /smbshare/
[root@s1 ~]# semanage fcontext -a -t samba_share_t '/smbshare(/.*)?'
[root@s1 ~]# restorecon -vvFR /smbshare/
在/etc/samba/smb.conf加上几行
[smbshare]
path = /smbshare
write list = @marketing
[root@s1 ~]# useradd -s /sbin/nologin -G marketing brian
[root@s1 ~]# smbpasswd -a brian
[root@s1 ~]# useradd -s /sbin/nologin rob
[root@s1 ~]# smbpasswd -a rob
Client
1. 创建用户
[root@r7-h1 ~]# useradd brian
2. 创建挂载点
[root@r7-h1 ~]# mkdir /mnt/multiuser/
3. 自动挂载配置
[root@r7-h1 ~]# echo 'username=brian' > /root/smb-multiuser.txt
[root@r7-h1 ~]# echo 'password=redhat' >> /root/smb-multiuser.txt
在/etc/fstab加上一行
//192.168.122.243/smbshare /mnt/multiuser cifs credentials=/root/smb-multiuser.txt,multiuser,sec=ntlmssp 0 0
4. 挂载
[root@r7-h1 ~]# mount /mnt/multiuser/
5. 切换用户,尝试创建文件。
[root@r7-h1 ~]# su - brian
[brian@r7-h1 ~]$ cifscreds add 192.168.122.243
[brian@r7-h1 ~]$ echo "Multiuser" > /mnt/multiuser/brian2.txt
[brian@r7-h1 ~]$ cat /mnt/multiuser/brian2.txt
Multiuser
[root@r7-h1 ~]# useradd rob
[root@r7-h1 ~]# su - rob
[rob@r7-h1 ~]$ cifscreds add 192.168.122.243
[rob@r7-h1 ~]$ echo "Multiuser" > /mnt/multiuser/rob2.txt
-bash: /mnt/multiuser/rob2.txt: Permission denied