linux之samba

samba

1.定义

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


2.配置

2.1 安装
[root@localhost ~]# yum install samba samba-common samba-client -y
Samba – 服务器应用程序
Samba-common – Samba的支持文件
Samba-client – 客户端应用程序
 服务名称:smb nmb
[root@localhost ~]# systemctl start smb nmb
[root@localhost ~]# systemctl enable smb nmb
添加用户
[root@localhost ~]# smbpasswd -a student    添加用户
[root@localhost ~]# pdbedit -L               查看用户    
pdbedit -x   smb用户
[root@localhost ~]# getsebool -a | grep samba
[root@localhost ~]# setsebool -P samba_enable_home_dirs on


2.2.共享目录

[root@localhost ~]# vim /etc/samba/smb.conf

添加

         [hahha]               共享文件名称

        comment = sharedir    对共享文件的描述
        path = 共享文件 (/mnt  /sharesmb)

[root@localhost ~]# systemctl restart smb.service


测试:
smbclient  -L  //172.25.254.121/hahaha
Enter student's password:



2.2.2当共享目录为用户自建目录时
        更改文件的安全上下文
        semanage fcontext -a -t  samba_share_t '/smbshare(/.*)?'

        restorecon -RvvF /smbshare

测试:
smbclient //172.25.254.121/student -U student
Enter student's password:



2.2.3当共享目录为系统目录时


    setsebool -P samba_export_all_ro on    #只读共享

    setsebool -P samba_export_all_rw on    #读写共享

测试:
smbclient //172.25.254.121/student -U student
Enter student's password:



2.3 配置参数,控制访问
 2.3.1  匿名用户访问
125             map to guest = bad user
                   guest ok = yes

测试:
smbclient //172.25.254.121/hahaha
Enter student's password:



2.3.2访问控制
     
       hosts allow = 172.25.254.21    #仅允许
       hosts deny = 172.25.254.21    #仅拒绝

测试:
smbclient  //172.25.254.121/hahaha  -U student
Enter student's password:


        valid users = redhat           当前共享的有效用户为redhat
        valid users = +redhat        当前共享的有效用户为redhat组
        valid users = @redhat        当前共享的有效用户为redhat组
        useradd -s /sbin/nologin redhat
        smbpasswd -a redhat
        pdbedit redhat
        usermod -G redhat student

2.3.3读写控制   所有用户的都可以写 

[root@localhost ~]# getsebool -a | grep samba
[root@localhost ~]# setsebool -P samba_export_all_rw on
[root@localhost ~]# chmod o+w /mnt
[root@localhost ~]# vim /etc/samba/smb.conf
    writable = yes

2.3.3读写控制   指定用户可写
#某一个人可写或某一组可写

            writable = no
            write list =  student
            write list =  +student
            write list =  @student

#某一个人以root用户写

         chmod o-w /mnt/
         writable = yes

        admin users = student



2.4  samba多用户认证

##在客户端

[root@foundation21 /]# vim /root/haha
[root@foundation21 kiosk]# cat /root/haha
username=student
password=student

[root@foundation21 /]# chmod 600 /root/haha
[root@foundation21 /]# yum install cifs-utils -y

[root@foundation21 /]# umount /mnt/
[root@foundation21 /]# mount -o credentials=/root/haha,multiuser,sec=ntlmssp  //172.25.254.121/hahha /mnt/
###credentials=/root/haha    指定挂载时所用到的用户文件
###multiuser            支持多用户认证
###sec=ntlmssp            认证方式为标准smb认证方式
[root@foundation21 /]# su - kiosk
[kiosk@foundation21 ~]$ ls /mnt
ls: cannot access /mnt: Permission denied     ###因为没有做smb的认证,所以无法访问smb共享
[kiosk@foundation21 ~]$ cifscreds add -u redhat 172.25.254.121
Password:                                     ###smb用户redhat的密码
[kiosk@foundation21 ~]$ ls /mnt/

file  file1  file2


 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值