2018-9-11日常作业:SAMBA搭建共享服务器

1.搭建匿名用户共享服务器
2.搭建用户认证共享服务器
要求:
1.不论是匿名用户还是用户认证共享,均要在客户机验证结果
2.用户认证共享需要映射系统用户为一个虚拟用户
这里写图片描述
配置环境

主机端 客户端
192.168.88.128 192.168.88.129

1.搭建匿名用户共享服务器

1.搭建前准备

[root@localhost ~]# vim /etc/sysconfig/selinux       关闭selinux,修改完成后重启SELINUX修改为disabled
[root@localhost ~]# sestatus 
SELinux status:                 disabled
[root@localhost ~]# systemctl stop firewalld.service          关闭防火墙

2.安装SAMBA服务

[root@localhost ~]# yum install samba-* -y                 安装SAMBA服务
[root@localhost ~]# service smb status                       查看SAMBA服务运行状态
Redirecting to /bin/systemctl status smb.service
● smb.service - Samba SMB Daemon
   Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@localhost ~]# systemctl start smb                   
[root@localhost ~]# systemctl status smb                 启动SAMBA服务
● smb.service - Samba SMB Daemon
   Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2018-09-11 10:07:51 CST; 13s ago
 Main PID: 2491 (smbd)
   Status: "smbd: ready to serve connections..."
    Tasks: 4
   CGroup: /system.slice/smb.service
           ├─2491 /usr/sbin/smbd --foreground --no-process-group
           ├─2495 /usr/sbin/smbd --foreground --no-process-group
           ├─2496 /usr/sbin/smbd --foreground --no-process-group
           └─2498 /usr/sbin/smbd --foreground --no-process-group

911 10:07:51 localhost.localdomain systemd[1]: Starting Samba SMB Daemon...
911 10:07:51 localhost.localdomain smbd[2491]: [2018/09/11 10:07:51.326367,  0] ../lib/util/bec...dy)
911 10:07:51 localhost.localdomain systemd[1]: Started Samba SMB Daemon.
911 10:07:51 localhost.localdomain smbd[2491]:   STATUS=daemon 'smbd' finished starting up and ...ons
Hint: Some lines were ellipsized, use -l to show in full.

3.配置SAMBA服务

[root@localhost ~]# vi /etc/samba/smb.conf
      [global]
              workgroup = SAMBA
               security = user
               map to guest=bad user      添加改行,共享级别,用户不需要账号和密码即可访问
      [public]                                                  
               comment = Public 
               path = /niming                  指定共享的目录
               public = yes                       允许所有人查看
[root@localhost ~]# mkdir /niming        创建共享目录
[root@localhost ~]# chmod 777 /niming/
[root@localhost ~]# chown -R nobody:nobody /niming/       设置nobody权限
[root@localhost ~]# systemctl start smb                       重启samba                     

4.客户端

[root@localhost ~]# smbclient -L 192.168.88.128 -u       查看samba有哪些资源
Enter SAMBA\root's password: 

    Sharename       Type      Comment
    ---------       ----      -------
    print$          Disk      Printer Drivers
    public          Disk      Public
    IPC$            IPC       IPC Service (Samba 4.7.1)
Reconnecting with SMB1 for workgroup listing.

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------
[root@localhost ~]# mount -t cifs //192.168.88.128/public /mnt/ -o username='Bad User'samba服务器的资源挂载到本地,如果有密码,还需要在后面加上password=密码,但这里是匿名用户,是没有密码的
[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   17G  2.0G   16G   12% /
devtmpfs                 476M     0  476M    0% /dev
tmpfs                    488M     0  488M    0% /dev/shm
tmpfs                    488M  7.7M  480M    2% /run
tmpfs                    488M     0  488M    0% /sys/fs/cgroup
/dev/sda1               1014M  130M  885M   13% /boot
tmpfs                     98M     0   98M    0% /run/user/0
//192.168.88.128/public   47G  4.8G   43G   11% /mnt

5.查看效果

1.主机端创建文件

[root@localhost ~]# cd /niming/
[root@localhost niming]# touch hello-world
[root@localhost niming]# ls
hello-world

2.客户端查看

[root@localhost mnt]# ls
hello-world
[root@localhost mnt]# rm -rf *
rm: 无法删除"hello-world": 只读文件系统
[root@localhost mnt]# mkdir ni-hao
mkdir: 无法创建目录"ni-hao": 权限不够             这里我们在文件/etc/samba/smb.conf没有设置writable,所以这儿是默认的NO,如想想要设置,在文件内加入writable=yes即可

3.主机端添加权限

[root@localhost ~]# vim /etc/samba/smb.conf
[public]
        comment = Public
        path = /niming
        public = yes
        writable=yes
[root@localhost mnt]# touch ni-hao

4.客户端添加文件

[root@localhost mnt]# touch ni-hao
[root@localhost mnt]# ll
总用量 0
-rw-r--r--. 1 root   root   0 9月  11 11:04 hello-world
-rw-r--r--. 1 nobody nobody 0 9月  11 15:15 ni-hao

4.主机端查看更改

[root@localhost ~]# cd /niming/
[root@localhost niming]# ll
总用量 0
-rw-r--r-- 1 root   root   0 9月  11 11:04 hello-world
-rw-r--r-- 1 nobody nobody 0 9月  11 15:15 ni-hao

注:这里要求的是匿名用户共享服务器,所以要在/etc/samba/smb.conf加入public=yes同意匿名用户访问,但是我们前面已应使用chown -R nobody:nobody命令,同意匿名用户访问/niming文件

2.搭建用户认证共享服务器

1.配置SAMBA服务

[root@localhost ~]# useradd -M kong     新建用户kong
[root@localhost ~]# smbpasswd -a kong     为用户kong创建密码
New SMB password:
Retype new SMB password:
Added user kong.
[root@localhost ~]# echo 'kong = bai'> /etc/samba/smbusers     将用户kong映射为bai(bai为不存在的用户),保存到文件中
[root@localhost ~]# vim /etc/samba/smb.conf

[global]
        workgroup = SAMBA
        security = user
        username map = /etc/samba/smbusers        为文件插入这一行
[root@localhost ~]# mkdir /kongbai
[root@localhost ~]# chown -R kong.kong /kongbai/       创建目录并更改所属用户和组
[root@localhost ~]# vim /etc/samba/smb.conf
[kongbai]                             插入以下内容
        comment = kongbai
        path = /kongbai
        browseable = yes
        guest ok = yes
        writable = yes
        write list = bai
        public = yes
[root@localhost ~]# systemctl start smb

2.客户端配置

[root@localhost ~]# smbclient -L 192.168.88.128 -U bai
Enter SAMBA\bai's password: 

    Sharename       Type      Comment
    ---------       ----      -------
    print$          Disk      Printer Drivers
    public          Disk      Public
    IPC$            IPC       IPC Service (Samba 4.7.1)
    kong            Disk      kong
Reconnecting with SMB1 for workgroup listing.

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------
[root@localhost ~]# mount -t cifs //192.168.88.128/kongbai /mnt/ -o username=bai,password=cl1996.   (我这里是还原了镜像,所以继续挂载到mnt,所以一般都选择新位置挂载)
[root@localhost ~]# df -h
文件系统                  容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root    17G  2.0G   16G   12% /
devtmpfs                  476M     0  476M    0% /dev
tmpfs                     488M     0  488M    0% /dev/shm
tmpfs                     488M  7.7M  480M    2% /run
tmpfs                     488M     0  488M    0% /sys/fs/cgroup
/dev/sda1                1014M  130M  885M   13% /boot
tmpfs                      98M     0   98M    0% /run/user/0
//192.168.88.128/kongbai   47G  4.8G   43G   11% /mnt

3.查看效果

1.主机端

[root@localhost ~]# cd /kongbai/
[root@localhost kongbai]# ls
[root@localhost kongbai]# touch hello-world
[root@localhost kongbai]# ll
总用量 0
-rw-r--r-- 1 root root 0 911 17:17 hello-world

2.客户端

[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ll
总用量 0
-rw-r--r-- 1 root root 0 911 17:17 hello-world
[root@localhost mnt]# ll
总用量 0
-rw-r--r-- 1 root root 0 911 17:17 hello-world
[root@localhost mnt]# rm -rf *
[root@localhost mnt]# touch ni-hao
[root@localhost mnt]# ll
总用量 0
-rw-r--r-- 1 1001 1001 0 911 17:18 ni-hao   由于我没有kong这个用户,所以显示GIDUID,因为bai是映射的kong的虚拟用户,所有这里的1001不是bai这个用户和组

3.主机端

[root@localhost kongbai]# ll
总用量 0
-rw-r--r-- 1 kong kong 0 9月  11 17:18 ni-hao

猜你喜欢

转载自blog.csdn.net/Empty_city_dreams/article/details/82629344