########samba####
1.samba作用
提供cifs协议实现文件共享
2.安装
[root@localhost ~]# yum install samba samba-common samba-client -y
[root@localhost ~]# systemctl start smb nmb
[root@localhost ~]# systemctl enable smb nmb
ln -s '/usr/lib/systemd/system/smb.service' '/etc/systemd/system/multi-user.target.wants/smb.service'
ln -s '/usr/lib/systemd/system/nmb.service' '/etc/systemd/system/multi-user.target.wants/nmb.service'
3.添加smb用户
smb用户必须是本地用户
[root@localhost ~]# smbpasswd -a student ##添加用户student
New SMB password: ##输入smb密码
Retype new SMB password: ##确认密码
Added user student.
[root@localhost ~]#
pdbedit -L ##查看smb用户信息
pdbedit -x smb用户 ##删除smb用户
[root@localhost ~]# setsebool -P samba_enable_home_dirs 1 ##在selinux中设定smb用户可以访问自己的家目录
测试:
[kiosk@foundation6 Desktop]$ smbclient //172.25.254.106/student -U student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Fri Jul 11 07:06:52 2014
.. D 0 Fri Jul 11 06:19:09 2014
.bash_logout H 18 Wed Jan 29 20:45:18 2014
.bash_profile H 193 Wed Jan 29 20:45:18 2014
.bashrc H 231 Wed Jan 29 20:45:18 2014
.ssh DH 0 Fri Jul 11 06:19:10 2014
.config DH 0 Fri Jul 11 07:06:53 2014
10473900 blocks of size 1024. 7308584 blocks available
smb: \>
4.共享目录的基本设定
[root@localhost ~]# vim /etc/samba/smb.conf
[hello] ##共享名称
comment = dir ##对共享目录的描述
path = /westos ##共享目录的绝对路径
[root@localhost ~]# systemctl restart smb.service
当共享目录为用户自建立目录时:
semanage fcontext -a -t samba_share_t '/westos(/.*)?
restorecon -RvvF /westos
测试结果:
[kiosk@foundation6 Desktop]$ smbclient //172.25.254.106/hello -U student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Sat Jun 3 14:33:02 2017
.. D 0 Sat Jun 3 14:32:35 2017
kkk N 0 Sat Jun 3 14:33:02 2017
10473900 blocks of size 1024. 7307596 blocks available
smb: \>
当共享目录为系统建立目录时:
setsebool -P samba_export_all_ro on ##只读共享
setsebool -P samba_export_all_rw on ##读写共享
5.samba的配置参数
vim /etc/samba/smb.conf ##参数配置修改该文件内容
#匿名用户访问
guest ok = yes
map to guest = bad user
测试结果:
[kiosk@foundation6 Desktop]$ smbclient //172.25.254.106/hello
Enter kiosk's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Sat Jun 3 14:50:43 2017
.. D 0 Sat Jun 3 14:50:34 2017
ll N 0 Sat Jun 3 14:50:43 2017
10473900 blocks of size 1024. 7308180 blocks available
smb: \>
#访问控制
hosts allow = ##仅允许
hosts deny = ##仅拒绝
valid users = ##当前共享的有效用户
valid users = westos ##当前共享的有效用户为westos
valid users = @westos ##当前共享的有效用户为westos组
valid users = +westos ##当前共享的有效用户为westos组
##读写控制
所有用户均可写
chmod o+w /mnt ##共享目录加权限
setsebool -P samba_export_all_rw on ##开启selinux的读写功能
vim /etc/samba/smb.conf
writable = yes ##所有用户可写
测试:
[root@foundation6 Desktop]# mount -o username=student,password=student //172.25.254.106/hello /mnt/
[root@foundation6 Desktop]# touch /mnt/hi
[root@foundation6 Desktop]# touch /mnt/hello
共享的目录:
[root@localhost ~]# cd /westos
[root@localhost westos]# ll
total 0
-rw-r--r--. 1 student student 0 Jun 3 03:51 hello
-rw-r--r--. 1 student student 0 Jun 3 03:51 hi
-rw-r--r--. 1 root root 0 Jun 3 02:50 ll
[root@localhost westos]#
设定指定用户可写
write list = student ##可写用户
write list = +student ##可写用户组
write list = @student
admin users = westos ##共享的超级用户指定
6.smb多用户挂载
在client上
vim /root/westos
username =student
password =student
chmod 600 /root/westos
yum install cifs-utils -y
mount -o credentials=/root/westos,multiuser,sec=ntlmssp //172.25.254.106/hello /mnt/
##credentials=/root/westos 指定挂载时所用到的用户文件
#multiuser 支持多用户认证
#sec=ntlmssp 认证方式为标准smb认证方式
su - kiosk
ls /mnt
ls: cannot access /mnt: Permission denied ##没有smb认证,无法进行共享
cifscreds add -u westos 172.25.254.106
Password: ##smb用户westos的密码