smb

1.安装服务

[root@client ~]# yum install samba samba-common samba-client.x86_64 -y

[root@client ~]# systemctl start smb nmb

[root@client ~]# systemctl enable smb nmb


2.添加用户

[root@client ~]# smbpasswd -a student ##添加student用户

New SMB password: ##输入smb当前用户密码

Retype new SMB password: ##确认密码

Added user student.

[root@client ~]# pdbedit -L ##列出所有用户名

student:1000:User student[root@client ~]# pdbedit -x student ##删除用户名

[root@client ~]# setsebool samba_enable_home_dirs=1 ##在selinux上设置布尔值使smb用户可以访问自己的家目录


3.共享目录设定

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

[haha] ##共享名称  

comment = local directory ##对共享目录的描述  

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


当共享目录为用户自建目录时

[root@localhost ~]# semanage fcontext -a -t samba_share_t '/smbshare(/.*)?'    ##更改目录及其以下所有文件的安全上下文
[root@localhost ~]# restorecon -RvvF /smbshare/                    ##刷新

当共享目录为系统建立目录时

[root@localhost ~]# vim /etc/samba/smb.conf 
        [haha]
        comment = local directory
        path = /etc
        workgroup = WESTOS
[root@localhost ~]# setsebool -P samba_export_all_ro on        ##只读共享
[root@localhost ~]# setsebool -P samba_export_all_rw on        ##读写共享

匿名用户

[root@localhost ~]# vim /etc/samba/smb.conf 
125         map to guest = bad user     ##将所有samba系统主机所不能正确识别的用户都映射成guest用户
            guest ok = yes              ##允许guest登录

访问控制

hosts allow =       ##仅允许
hosts deny =        ##仅拒绝 

valid users = ##当前共享的有效用户  

valid users = westos ##当前共享的有效用户 

westos valid users = @westos ##当前共享的有效用户为westos组 

valid users = +westos ##当前共享的有效用户为westos组


读写控制

所有用户均可写

[root@localhost ~]# chmod o+w /mnt
[root@localhost ~]# setsebool -P samba_export_all_rw on
[root@localhost ~]# vim /etc/samba/smb.conf 
        writable = yes
 
 
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

设定指定用户可写

[root@localhost ~]# vim /etc/samba/smb.conf 
        write list = student    ##可写用户
    admin users = westos    ##共享的超级用户组
    write list = @student   ##可写用户组
    write list = +student
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

测试

mount -o username=student,password=redhat //172.25.254.119/haha /mnt
touch

smb多用户挂载

在client上


vim /root/haha          ##用户文件
username=student
password=redhat

chmod 600 /root/haha
yum install cifs-utils -y
mount -o credentials=/root/haha,multiuser,sec=ntlmssp //172.25.254.119/haha /mnt
##credentoals=/root/haha 指定挂载时所用到的用户文件
##multiuser      支持多用户认证
##sec=ntlmssp        认证方式为标准smb认证方式
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

测试

su - kiosk
ls /mnt
ls: cannot access /mnt: Permission denied   ##因为没有做smb的认证 所以无法访问smb共享

cifscreds add -u westos 172.25.254.119      ##添加用户认证
Password:       ##smb用户认证的密码
ls /mnt

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值