SMB文件共享——实验篇

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SMB文件共享——实验篇相关的知识,希望对你有一定的参考价值。

实验环境:RHEL7.0

             服务器    server1.example.com    172.25.254.1

             客户端    server2.example.com    172.25.254.2


1.安装配置SMB

    1.1安装

[[email protected] ~]# yum install samba samba-client -y

[[email protected] ~]# systemctl start smb

[[email protected] ~]# systemctl enable smb

    1.2配置火墙策略

[[email protected] ~]#  firewall-cmd --permanent --add-service=samba 

[[email protected] ~]# firewall-cmd --permanent --add-service=samba-client

[[email protected] ~]# firewall-cmd --reload

    1.3添加smb用户

[[email protected] ~]# useradd willis     ##创建用户

[[email protected] ~]# useradd student

[[email protected] ~]# smbpasswd -a willis    ##新建为smb用户并加密

New SMB password:

Retype new SMB password:

Added user willis.

[[email protected] ~]# smbpasswd -a student

New SMB password:

Retype new SMB password:

Added user student.

[[email protected] ~]# pdbedit -L

willis:1001:

student:1002:

[[email protected] ~]# smbclient -L //172.25.254.1 -U student  

Enter student‘s password: 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]


Sharename       Type      Comment

---------       ----      -------

IPC$            IPC       IPC Service (Samba Server Version 4.1.1)

student         Disk      Home Directories

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]


Server               Comment

---------            -------


Workgroup            Master

---------            -------

[[email protected] ~]# smbclient  //172.25.254.1/student -U student

Enter student‘s password: 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Thu Sep 22 18:33:14 2016

  ..                                  D        0  Thu Sep 22 18:33:14 2016

  .mozilla                           DH        0  Thu Aug  4 23:45:35 2016

  .bash_logout                        H       18  Wed Jan 29 20:45:18 2014

  .bash_profile                       H      193  Wed Jan 29 20:45:18 2014

  .bashrc                             H      231  Wed Jan 29 20:45:18 2014


34808 blocks of size 262144. 22711 blocks available

smb: \> quit


 2. 改共享目录 

    2.1 自建目录

[[email protected] ~]# mkdir /share

[[email protected] ~]# vim /etc/samba/smb.conf 

       [test]

       comment = test share

       path = /share

[[email protected] ~]# touch /share/file

[[email protected] ~]# smbclient //172.25.254.1/test -U willis

Enter willis‘s password: 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Thu Sep 22 20:15:26 2016

  ..                                  D        0  Thu Sep 22 18:41:38 2016

  file                                N        0  Thu Sep 22 20:15:26 2016


34808 blocks of size 262144. 22696 blocks available

smb: \> 

    2.2共享系统目录

[[email protected] ~]# vim /etc/samba/smb.conf 

       [test]

       comment = test share

       path = /mnt

[[email protected] ~]# ls /mnt/

[[email protected] ~]# touch /mnt/file1

[[email protected] ~]# smbclient //172.25.254.1/test -U willis

Enter willis‘s password: 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Thu Sep 22 20:18:31 2016

  ..                                  D        0  Thu Sep 22 18:41:38 2016

  file1                               N        0  Thu Sep 22 20:18:31 2016


34808 blocks of size 262144. 22696 blocks available

smb: \> 


3. 改工作组

[[email protected] ~]# smbclient -L //172.25.254.1 -U willis

Enter willis‘s password: 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]


Sharename       Type      Comment

---------       ----      -------

test            Disk      test share

IPC$            IPC       IPC Service (Samba Server Version 4.1.1)

willis          Disk      Home Directories

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]


Server               Comment

---------            -------


Workgroup            Master

---------            -------

[[email protected] ~]# 

[[email protected] ~]# vim /etc/samba/smb.conf 

         workgroup = willis

[[email protected] ~]# smbclient -L //172.25.254.1 -U willis

Enter willis‘s password: 

Domain=[WILLIS] OS=[Unix] Server=[Samba 4.1.1]


Sharename       Type      Comment

---------       ----      -------

test            Disk      test share

IPC$            IPC       IPC Service (Samba Server Version 4.1.1)

willis          Disk      Home Directories

Domain=[WILLIS] OS=[Unix] Server=[Samba 4.1.1]


Server               Comment

---------            -------


Workgroup            Master

---------            -------

[[email protected] ~]# 



 4. 允许/拒绝访问服务的主机设置

[[email protected] ~]# vim /etc/samba/smb.conf   (随改立即生效)

         hosts deny = 172.25.254.2

    测试:

[[email protected] ~]# smbclient -L //172.25.254.1 -U willis

Enter willis‘s password: 

protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE


5.客户端挂载使用

    RHEL6 可匿名登陆并挂载(share级别) 

    RHEL 7 不能匿名挂载

服务器端:

[[email protected] ~]# vim /etc/samba/smb.conf 

        security = user

        passdb backend = tdbsam

        map to guest = bad user    #添加此句


      [test]

      comment = test share

      path = /share

      guest ok = yes   #添加此句

[[email protected] ~]# systemctl restart smb.service

客户端:

[[email protected] mnt]# mount //172.25.254.1/test /mnt -o username=willis,password=redhat

[[email protected] mnt]# df -h

//172.25.254.1/test    8.5G  3.0G  5.6G  35% /mnt


常用参数

[test]

Guest ok  = yes    # 匿名用户可登陆

Browseable = no    #隐藏共享

Writable = yes     #允许所有用户写入

Weite list =  student   #只允许student写入

Write list = +student

Write list = @student    #允许student用户组写入  +和@功能一样

Valid users = +student    #test这个组只能student用户组使用

Admin users = student    # student是以root身份运行


本文出自 “技术人生,简单不简单” 博客,请务必保留此出处http://willis.blog.51cto.com/11907152/1855587

以上是关于SMB文件共享——实验篇的主要内容,如果未能解决你的问题,请参考以下文章

配置SMB文件夹共享实验步骤

全面分析RHCE7(红帽认证工程师)考试题目之 ----Samba文件共享篇

samba

Windows上面挂载NFS共享

linux系统smb安装,windows访问smb共享文件夹和虚拟机vm与真机的互ping

搭建文件共享服务器-samba 匿名和用户验证访问