Samba服务的匿名访问用户访问以及权限控制

一、samba服务概述

  • 在windows网络环境中,主机之间进行文件和打印机共享是通过微软公司自己的SMB/CIFS实现的。SMB(server Message Block 服务消息块)和CIFS(Common Internet File System,通用互联网文件系统)协议是微软的私有协议,在Samba项目出现之前,并不能与Linux/UNIX系统进行通信。
  • Samba是著名的开源软件项目之一,它在Linux/UNIX系统中实现了微软的SMB/CIFS网络协议,使得跨平台的文件共享变得更容易。

二、 Samba服务的配置

2.1 安装DHCP服务

[root@localhost ~]# yum -y install dhcp  ## 安装DHCP服务
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf   ## 进入dhcp配置文件
subnet 192.168.100.0 netmask 255.255.255.0 {          ##  添加以下配置文件
   range 192.168.100.10 192.168.100.200;
   option routers 192.168.100.1;
   option domain-name-servers 8.8.8.8;
}
[root@localhost ~]# iptables -F  ## 清空防火墙配置
[root@localhost ~]# setenforce 0 ## 关闭核心防护
[root@localhost ~]# systemctl start dhcpd  ## 开启dhcp服务

2.2 win10通过DHCP 获取地址

在这里插入图片描述
在这里插入图片描述

2.3 安装并配置Samba服务

## 这里为了防止干扰 用的仅主机模式    需要配置本地yum源  yum本地配置见前面文章
[root@localhost ~]# yum install samba -y
[root@localhost ~]# cd /etc/samba/
[root@localhost samba]# ll
总用量 24
-rw-r--r--. 1 root root    20 10月 31 2018 lmhosts
-rw-r--r--. 1 root root   545 7月  15 19:22 smb.conf  ## samba 配置文件
-rw-r--r--. 1 root root 11327 10月 31 2018 smb.conf.example
[root@localhost samba]# cp  smb.conf smb.conf.bak  ##备用一个备份文件 

2.3.1 修改samba配置文件 匿名访问


security = user              ## 匿名访问
map to guest = Bad User

[share]
        comment = share Drivers
        path = /opt/abc  ## 文件路径
        public=yes  ## 共享允许 
        writable=yes  ## 可写
        create mask = 0664
        directory mask = 0775

  • 进入在opt下创建abc文件
[root@localhost samba]# mkdir /opt/abc
[root@localhost samba]# chmod 777 /opt/abc/ ## 修改协议  可读可写
[root@localhost samba]# ll  /opt/
总用量 0
drwxrwxrwx. 2 root root 6 7月  15 19:35 abc
drwxr-xr-x. 2 root root 6 10月 31 2018 rh

2.3.2 启动Samba服务

[root@localhost samba]# systemctl start smb 
  • 查看服务
[root@localhost abc]# netstat -atpn             ## 发现Samba的端口
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:139             0.0.0.0:*               LISTEN      16801/smbd          ##samba 协议的服务端口
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:6000            0.0.0.0:*               LISTEN      9943/X              
tcp        0      0 192.168.100.100:53      0.0.0.0:*               LISTEN      12977/named         
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      12977/named         
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      9747/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      9356/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      9354/cupsd          
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      12977/named         
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      9746/master         
tcp        0      0 0.0.0.0:445             0.0.0.0:*               LISTEN      16801/smbd          
tcp        0      0 192.168.100.100:445     192.168.100.10:49709    ESTABLISHED 16864/smbd          
tcp6       0      0 :::139                  :::*                    LISTEN      16801/smbd          
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::6000                 :::*                    LISTEN      9943/X              
tcp6       0      0 ::1:53                  :::*                    LISTEN      12977/named         
tcp6       0      0 :::22                   :::*                    LISTEN      9356/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      9354/cupsd          
tcp6       0      0 ::1:953                 :::*                    LISTEN      12977/named         
tcp6       0      0 ::1:25                  :::*                    LISTEN      9746/master         
tcp6       0      0 :::445                  :::*                    LISTEN      16801/smbd       ##samba 协议的服务端口
  • 在win10 上
    在这里插入图片描述
    在这里插入图片描述
  • 在 CentOS 上面查看win10 新建的文件
[root@localhost samba]# vim smb.conf
[root@localhost samba]# cd /opt/abc/
[root@localhost abc]# ls
123.txt

  • 发现新建的文件属主和属组都是nobody
[root@localhost abc]# cd /opt/abc/
[root@localhost abc]# ll
总用量 0
-rw-rw-r--. 1 nobody nobody 0 7月  15 20:09 123.txt

2.3.4用户密码登录访问

[root@localhost ~]# vim /etc/samba/smb.conf
 map to guest = Bad User    ## 去掉这行
### 文件末尾添加以下内容
[test]
        comment = test Drivers
        path = /opt/test
        browseable=yes
        public=yes
        create mask = 0664
        directory mask = 0775
        valid users=zhangsan,lisi   ## 可以访问的用户
        write list=zhangsan       ## 只有张三可以写
  • 创建用户 重启服务
[root@localhost opt]# mkdir test     ## 在opt下 创建test文件
[root@localhost opt]# chmod 777 test  ## 修改权限

[root@localhost ~]# useradd zhangsan
[root@localhost ~]# useradd lisi
[root@localhost ~]# smbpasswd -a zhangsan  ## 设置zhangsan的 samba密码
[root@localhost ~]# smbpasswd -a lisi  ## 设置lisi的samba密码
[root@localhost ~]# pdbedit -L    ## 查看samba用户
zhangsan:1001:
lisi:1002:
[root@localhost ~]# systemctl restart smb   ## 重启samba服务

  • win10 访问 \192.168.100.100

2.3.4.1以zhangsan用户访问samba服务

在这里插入图片描述
在这里插入图片描述

2.3.4.1 以lisi用户什么访问samba服务

  • 清空远程连接缓存
C:\Users\wang>net use * /d
你有以下的远程连接:

                    \\192.168.100.100\IPC$
继续运行会取消连接。

你想继续此操作吗? (Y/N) [N]: y
命令成功完成。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_47219725/article/details/107367945
今日推荐