cifs------网络文件系统(2)

接着上篇博客继续:

Samba 基本配置

[root@server2 ~]# rpm -qc samba-common             //查看smb的配置文件

1、黑、白名单的设定

默认白名单,设置的ip是黑名单用户:hosts deny = ip
默认黑名单,设置的ip是白名单用户:hosts allow = ip

黑名单 :

        假设不允许ip为172.25.1.2的的主机登陆

服务器端 :

[root@server1 ~]# vim /etc/samba/smb.conf           //编辑配置文件

hosts deny = 172.25.1.2

[root@server1 ~]# systemctl restart smb.service         //服务重启

此时,客户端:

[root@server2 ~]# smbclient -L //172.25.1.1/ -U student                 //服务被拒绝

白名单:

        假设只允许ip为172.25.1.2的的主机登陆

服务器端:

[root@server1 samba]# vim /etc/samba/smb.conf             //将黑名单注释掉,并添加白名单

[root@server1 ~]# systemctl restart smb.service        //重启服务

此时,客户端:

[root@server2 ~]#  smbclient //172.25.1.1/student -U student               //可以登陆

2、smb 共享目录

非系统目录的共享

服务器端:

[root@server1 ~]# mkdir /westos

[root@server1 ~]# touch /westos/file{1..5}           //目录下创建文件

修改安全上下文,这里出现了点问题;

[root@server1 ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?'              //提示没有semanage这个命令
-bash: semanage: command not found

[root@server1 ~]# yum install -y semanage   

Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
No package semanage available.
Error: Nothing to do

[root@server1 ~]# yum provides semanage       

Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
rhel7.5/filelists_db                                              | 3.4 MB  00:00:00     
policycoreutils-python-2.5-22.el7.x86_64 : SELinux policy core python utilities
Repo        : rhel7.5
Matched from:
Filename    : /usr/sbin/semanage

[root@server1 ~]# yum -y install policycoreutils-python

[root@server1 ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?'               //此时修改安全上下文

[root@server1 ~]# restorecon -FvvR /westos/                     //刷新

[root@server1 ~]# semanage fcontext -l | grep /westos           //过滤查看/westos的安全上下文修改是否成功

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

[DIR]                      //可以看到的共享目录的名称
comment = westos file   //对共享目录的描述
path = /westos                //共享目录的绝对路径

[root@server1 ~]# systemctl restart smb.service              //重启服务

客户端:

[root@server2 ~]# smbclient //172.25.1.1/DIR               //匿名登陆
Enter SAMBA\root's password:
Anonymous login successful
tree connect failed: NT_STATUS_ACCESS_DENIED             //登录失败,则匿名用户不可以登陆
[root@server2 ~]# smbclient //172.25.1.1/DIR -U student        //student登陆
Enter SAMBA\student's password:
Try "help" to get a list of possible commands.                  //登陆成功
smb: \> ls
  .                                   D        0  Tue Mar  5 07:17:42 2019
  ..                                 DR        0  Tue Mar  5 07:16:09 2019
  file1                               N        0  Tue Mar  5 07:17:42 2019
  file2                               N        0  Tue Mar  5 07:17:42 2019
  file3                               N        0  Tue Mar  5 07:17:42 2019
  file4                               N        0  Tue Mar  5 07:17:42 2019
  file5                               N        0  Tue Mar  5 07:17:42 2019

        17811456 blocks of size 1024. 16542024 blocks available
smb: \> quit                 //退出

系统目录的共享

服务端:

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

[root@server1 ~]# systemctl restart smb.service                
[root@server1 ~]# setsebool -P samba_export_all_ro on              //打开该布尔值后可以共享所有目录,比安全上下文的级别高

[root@server1 ~]# ls /mnt
westos

客户端:

[root@server2 ~]# smbclient //172.25.1.1/DIR -U student

smb 权限管理

browseable = no | yes ——更改此参数,不用重启服务
no ——将该共享目录设置为隐藏
yes——将该共享目录设置为显示
writable = yes|no ——更改此参数,需要重启服务

no | yes —— 设置用户是否可写(所有用户)
write list = student ——更改此参数,需要重启服务

允许用户 student 进行写操作(相当于白名单)
write list = @student ——更改此参数,需要重启服务

只允许属于 student 组的用户进行写操作
admin users = 用户名 ——更改此参数,需要重启服务

1.隐藏该共享目录

服务端:

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

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

客户端:

[root@server2 ~]#  smbclient -L //172.25.1.1

2.显示该共享目录,且可写

服务器端:

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

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

[root@server1 ~]# chmod 777 /mnt

客户端:

[root@server2 ~]# mount //172.25.1.1/DIR /mnt -o username=student,password=redhat

[root@server2 ~]# mount //172.25.1.1/DIR /mnt -o username=student,password=redhat
[root@server2 ~]# cd /mnt/
[root@server2 mnt]# ls
westos
[root@server2 mnt]# touch file1
[root@server2 mnt]# ls
file1  westos

[root@server2 mnt]# cd
[root@server2 ~]# umount /mnt/


**************************************

以此类推。。。。。。

smb 多用户挂载

客户端:

[root@server2 ~]# yum install cifs-utils -y

[root@server2 ~]# vim /root/smbpass               //根据挂载规则编写认证所需的文件

[root@server2 ~]# mount -o credentials=/root/smbpass,sec=ntlmssp,multiuser //172.25.1.1/DIR /mnt

//挂载,其中,credentials=/root/smbpass文件指定的用户名、密码,sec=ntlmssp 认证方式认证方式是ntlmssp;查询方式:rpm -ql | grep samba, multiuser为多用户挂载

[root@server2 ~]# df

[root@server2 ~]# cd /mnt/
[root@server2 mnt]# ls
file1  westos
[root@server2 mnt]# useradd file2        //创建用户file2
[root@server2 mnt]# su - file2         //切换到普通用户file2
[file2@server2 ~]$ cd /mnt             
[file2@server2 mnt]$ ls         //无法查看 ,必须指定用户挂载通过smb认证才可以查看

ls: reading directory .: Permission denied
[file2@server2 mnt]$ exit
logout

[root@server2 mnt]# cifscreds --help          //查看相关命令

cifscreds: unrecognized option '--help'
Usage:
    cifscreds add [-u username] [-d] <host|domain>
    cifscreds clear [-u username] [-d] <host|domain>
    cifscreds clearall
    cifscreds update [-u username] [-d] <host|domain>

[root@server2 mnt]# su - file2
Last login: Tue Mar  5 10:02:55 EST 2019 on pts/0
[file2@server2 ~]$ cifscreds add -u student 172.25.1.1                //需要通过smb认证
Password:
[file2@server2 ~]$ cd /mnt/
[file2@server2 mnt]$ ls            //此时可以查看mnt下面的文件

file1  westos

smb 匿名用户访问

服务器端:

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

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


客户端:

[root@server2 mnt]$ smbclient //172.25.1.1/DIR

//即匿名用户此时可以访问到

[root@server2 ~]# mount //172.25.1.1/DIR /mnt -o username=guest,password=""

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值