天天看點

SMB檔案共享——實驗篇

實驗環境:RHEL7.0

             伺服器    server1.example.com    172.25.254.1

             用戶端    server2.example.com 172.25.254.2

1.安裝配置SMB

    1.1安裝

[root@server1 ~]# yum install samba samba-client -y

[root@server1 ~]# systemctl start smb

[root@server1 ~]# systemctl enable smb

    1.2配置火牆政策

[root@server1 ~]#  firewall-cmd --permanent --add-service=samba 

[root@server1 ~]# firewall-cmd --permanent --add-service=samba-client

[root@server1 ~]# firewall-cmd --reload

    1.3添加smb使用者

[root@server1 ~]# useradd willis     ##建立使用者

[root@server1 ~]# useradd student

[root@server1 ~]# smbpasswd -a willis    ##建立為smb使用者并加密

New SMB password:

Retype new SMB password:

Added user willis.

[root@server1 ~]# smbpasswd -a student

Added user student.

[root@server1 ~]# pdbedit -L

willis:1001:

student:1002:

[root@server1 ~]# 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

Server               Comment

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

Workgroup            Master

[root@server1 ~]# smbclient  //172.25.254.1/student -U student

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 自建目錄

[root@server1 ~]# mkdir /share

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

       [test]

       comment = test share

       path = /share

[root@server1 ~]# touch /share/file

[root@server1 ~]# smbclient //172.25.254.1/test -U willis

Enter willis's password: 

  .                                   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共享系統目錄

       path = /mnt

[root@server1 ~]# ls /mnt/

[root@server1 ~]# touch /mnt/file1

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

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

3. 改工作組

[root@server1 ~]# smbclient -L //172.25.254.1 -U willis

test            Disk      test share

willis          Disk      Home Directories

[root@server1 ~]# 

         workgroup = willis

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

 4. 允許/拒絕通路服務的主機設定

[root@server1 ~]# vim /etc/samba/smb.conf   (随改立即生效)

         hosts deny = 172.25.254.2

    測試:

[root@server2 ~]# smbclient -L //172.25.254.1 -U willis

protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE

5.用戶端挂載使用

    RHEL6 可匿名登陸并挂載(share級别) 

    RHEL 7 不能匿名挂載

伺服器端:

        security = user

        passdb backend = tdbsam

        map to guest = bad user    #添加此句

      [test]

      comment = test share

      path = /share

      guest ok = yes   #添加此句

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

用戶端:

[root@server2 mnt]# mount //172.25.254.1/test /mnt -o username=willis,password=redhat

[root@server2 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身份運作

繼續閱讀