Linux学习篇第三章之~samba

来源:互联网 发布:win10 软件显示乱码 编辑:程序博客网 时间:2024/05/17 18:02
--------------------------------------------------------samba------------------------------------------------------------
1.samba作用

提供cifs协议实现共享文件

通用Internet文件系统(CIFS)也称为服务器信息块(SMB),是适用于MicrosoftWindows服务器和客户端的标准文件和打印机共享系统。Samba服务可用于将Linux文件系统作为CIFS/SMB网络文件共享进行共享,并将Linux打印机作为CIFS/SMB打印机共享进行共享。

2.安装
yum install samba samba-commn samba-client -y
systemctl start smb nmb
systemctl enable smb nmb
3.添加smb用户(smb用户必须是本地用户)
systemctl stop firewalld
smbpasswd -a student
               
[root@localhost ~]# pdbedit -L         ##查看smb用户信息
[root@localhost ~]# pdbedit -x smb     ##删除smb用户
setsebool -P samba_enable_home_dirs on ##在selinux中设定smb用户可以访问自己的家目录
4.共享目录的基本设定
 mkdir /smbshare
 touch /smbshare/westosxxx
 vim /etc/samba/smb.conf
               [hha]   ##共享名称
                comment = local directory  对共享目录的描述

               path = /smbshare           共享目录的绝对路径


> 当共享目录为用户自己建立目录时
semanage fcontext -a -t samba_share_t '/smbshare(/.*)?'
restorecon -RvvF /smbshare
systemctl restart smb.service
测试:
[kiosk@foundation43 Desktop]$ smbclient //172.25.254.143/hha -U student

> 当共享目录为系统建立目录时
setsebool -P samba export_all_ro on   ##只读共享
setsebool -P samba export_all_rw on  ##读写共享
touch /mnt/file{1..10}
systemctl restart smb.service
测试:

5.samba的配置参数
> 匿名用户访问
vim /etc/samba/smb.conf
            [hha]
             comment = local directory
             path = /mnt
             guest ok = yes

             hosts deny = bad user


测试:
[kiosk@foundation43 Desktop]$ smbclient //172.25.254.143/hha    ##匿名用户登陆                      

> 访问控制
hosts allow =      ##仅允许
hosts deny =       ##仅拒绝
valid users =      ##当前共享的有效用户
valid users = @westos  ##当前共享的有效用户为westos组
valid users = +westos  ##当前共享的有效用户为westos组

server:

vim /etc/samba/smb.conf


useradd westos -s /sbin/nologin

smbpasswd -a westos

usermod -G westos student
usermod -G westos student
 

测试:


> 读写控制(所有用户可写)
chmod o+w /mnt
setsebool -P samba_export_all_rw on
vim /etc/samba/smb.conf
  [hha]
  comment = local directory
  path = /mnt
  writable = yes
systemctl restart smb.service
测试:
 
(设定指定用户可写)
write list = student             ##可写用户
write list = +student           ##可写用户组
write list = @student
admin users = westos         ##共享的超级用户指定

测试:


6.smb多用户挂载(client)

[root@foundation155 ~]# vim /root/haha


[root@foundation155 ~]# chmod 600 /root/haha
[root@foundation155 ~]# yum install cifs-utils -y
[root@foundation155 ~]# mount -o credentials=/root/haha,multiuser,sec=ntlmssp //172.25.254.143/haha /mnt

##credentials=/root/haha 指定挂载时所用到的用户文件
##multiuser                 支持多用户认证
##sec=ntlmssp            认证方式为标准smb认证方式

测试:



原创粉丝点击