1. 程式人生 > >搭建Samba服務

搭建Samba服務

samba服務

題目:建立samba共享,共享目錄為/data,要求:(描述完整的過程)

1)共享名為shared,工作組為magedu;

2)添加組develop,添加用戶gentoo,centos和ubuntu,其中gentoo和centos以develop為附加組,ubuntu不屬於develop組;密碼均為用戶名;

3)添加samba用戶gentoo,centos和ubuntu,密碼均為“mageedu”;

4)此samba共享shared僅允許develop組具有寫權限,其他用戶只能以只讀方式訪問;

5)此samba共享服務僅允許來自於192.168.0.0/16網絡的主機訪問;


搭建環境:

Samba服務器:192.168.10.101 (CentOS 7)


相關程序包:

Samba服務端程序包:samba

Samba客戶端程序包:samba-client


搭建Samba詳細過程:


1、創建共享目錄/data

[[email protected] ~]# mkdir /data


2、創建系統用戶和組

[[email protected] ~]# useradd gentoo    # 創建用戶gentoo
[[email protected] ~]# useradd centos    # 創建用戶centos
[[email protected] ~]# useradd ubuntu    # 創建用戶ubuntu
[[email protected]
/* */ ~]# echo ‘gentoo‘ | passwd --stdin gentoo # 為用戶gentoo設置密碼 [[email protected] ~]# echo ‘centos‘ | passwd --stdin centos # 為用戶centos設置密碼 [[email protected] ~]# echo ‘ubuntu‘ | passwd --stdin ubuntu # 為用戶ubuntu設置密碼 [[email protected] ~]# groupadd develop # 創建組develop [[email protected]
/* */ ~]# usermod -aG develop gentoo # 添加用戶gentoo到組develop [[email protected] ~]# usermod -aG develop centos # 添加用戶centos到組develop


3、編輯Samba主配置文件/etc/samba/smb.conf,添加如下配置

[[email protected] ~]# vim /etc/samba/smb.conf
[global]
    workgroup = magedu
    
[shared]
    workgroup = magedu
    comment = data dir
    path = /data
    browseable = yes
    write list = @develop


4、檢查語法錯誤

[[email protected] ~]# testparm
[shared]
    comment = data dir
    path = /data
    hosts allow = 192.168.
    write list = @develop


5、為用戶centos、gentoo、ubuntu設置samba服務的密碼,密碼均為“mageedu”

[[email protected] ~]# smbpasswd -a centos
[[email protected] ~]# smbpasswd -a gentoo
[[email protected] ~]# smbpasswd -a ubuntu
或者:
[[email protected] ~]# pdbedit -a -u centos
[[email protected] ~]# pdbedit -a -u gentoo
[[email protected] ~]# pdbedit -a -u ubuntu
[[email protected] ~]# pdbedit -L    # 列出所有用戶
centos:2004:
gentoo:2003:
ubuntu:2005:


6、設置組develop對文件系統的有寫權限

[[email protected] ~]# setfacl -m g:develop:rwx /data


7、啟動samba服務

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


8、使用samba客戶端工具訪問

(1)查看共享

[[email protected] ~]# smbclient -L //192.168.10.101/shared -U centos
Enter centos‘s password: 
Domain=[MAGEDU] OS=[Windows 6.1] Server=[Samba 4.4.4]

	Sharename       Type      Comment
	---------       ----      -------
	shared          Disk      data dir
	IPC$            IPC       IPC Service (Samba Server Version 4.4.4)
	centos          Disk      Home Directories /home/centos
Domain=[MAGEDU] OS=[Windows 6.1] Server=[Samba 4.4.4]

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

	Workgroup            Master
	---------            -------
	SAMBA                WWW


(2)交互式訪問共享

#centos用戶

[[email protected] ~]# smbclient //192.168.10.101/shared -U centos
Enter centos‘s password: 
Domain=[MAGEDU] OS=[Windows 6.1] Server=[Samba 4.4.4]
smb: \> mkdir centos    # centos用戶能上傳文件,具有寫權限
smb: \> ls
  .                                   D        0  Sun Jun 11 10:28:46 2017
  ..                                 DR        0  Sun Jun 11 09:41:13 2017
  centos                              D        0  Sun Jun 11 10:27:45 2017

		52403200 blocks of size 1024. 46089400 blocks available


#gentoo用戶

[[email protected] ~]# smbclient //192.168.10.101/shared -U gentoo
Enter gentoo‘s password: 
Domain=[MAGEDU] OS=[Windows 6.1] Server=[Samba 4.4.4]
smb: \> mkdir gentoo    # gentoo用戶能上傳文件,具有寫權限
smb: \> ls
  .                                   D        0  Sun Jun 11 10:31:03 2017
  ..                                 DR        0  Sun Jun 11 09:41:13 2017
  centos                              D        0  Sun Jun 11 10:27:45 2017
  gentoo                              D        0  Sun Jun 11 10:31:03 2017

		52403200 blocks of size 1024. 46089360 blocks available


#ubuntu用戶

[[email protected] ~]# smbclient //192.168.10.101/shared -U ubuntu
Enter ubuntu‘s password: 
Domain=[MAGEDU] OS=[Windows 6.1] Server=[Samba 4.4.4]
smb: \> mkdir ubuntu    # ubuntu用戶不具有寫權限
NT_STATUS_MEDIA_WRITE_PROTECTED making remote directory \ubuntu


(3)掛載訪問共享


#centos用戶

[[email protected] ~]# mkdir /centos
[[email protected] ~]# mount -t cifs -o username=centos,password=magedu //192.168.10.101/shared /centos
[[email protected] ~]# cd /centos
[[email protected] centos]# ls
centos  gentoo
[[email protected] centos]# touch centos-file
[[email protected] centos]# ls
centos  centos-file  gentoo    # centos用戶具有寫權限


#gentoo用戶

[[email protected] ~]# mkdir /gentoo
[[email protected] ~]# mount -t cifs -o username=gentoo,password=magedu //192.168.10.101/shared /gentoo
[[email protected] ~]# cd /gentoo
[[email protected] gentoo]# ls
centos  centos-file  gentoo
[[email protected] gentoo]# touch gentoo-file
[[email protected] gentoo]# ls
centos  centos-file  gentoo  gentoo-file    # gentoo用戶具有寫權限


#ubuntu用戶

[[email protected] ~]# mkdir /ubuntu
[[email protected] ~]# mount -t cifs -o username=ubuntu,password=magedu //192.168.10.101/shared /ubuntu
[[email protected] ~]# cd /ubuntu
[[email protected] ubuntu]# ls
centos  centos-file  gentoo  gentoo-file
[[email protected] ubuntu]# touch ubuntu-file
touch: cannot touch ‘ubuntu-file’: Permission denied        # ubuntu用戶不具有寫權限


本文出自 “Tab” 博客,請務必保留此出處http://xuweitao.blog.51cto.com/11761672/1934201

搭建Samba服務