一 服務端配置
1 安裝所需軟件
[root@centos7 ~]# yum install samba samba-common -y
samba主要提供SMB服務所需的各項服務程序、相關的文件及其他和Samba相關的設置等
samba-common提供服務端和客戶端都會用的的數據,包括主配置文件、語法檢查等
2 添加Samba用戶
添加smb1、smb2、smb3,所屬組為centos組。
(1)添加系統用戶,因為Samba用戶必須是系統中已經存在的用戶
[root@centos7 ~]# useradd smb1 -G centos
[root@centos7 ~]# useradd smb2 -G centos
[root@centos7 ~]# useradd smb3 -G centos
(2)設置系統用戶為Samba用戶并修改密碼
smbpasswd [options] USERNAME
-a:添加
-x:刪除
-d:禁用
-e:啟用
[root@centos7 ~]# smbpasswd -a smb1
New SMB password:
Retype new SMB password:
Added user smb1.
[root@centos7 ~]# smbpasswd -a smb2
New SMB password:
Retype new SMB password:
Added user smb2.
[root@centos7 ~]# smbpasswd -a smb3
New SMB password:
Retype new SMB password:
Added user smb3.
(3)查看Samba用戶
pdbedit
-L:列出samba服務中的所有用戶;
-a, –create:添加用戶為samba用戶;
-u, –user=USER:要管理的用戶;
-x, –delete:刪除用戶;
-t, –password-from-stdin:從標準輸出接收字符串作為用戶密碼;使用空提示符,而后將密碼輸入兩次;
[root@centos7 ~]# pdbedit -L
smb1:1001:
smb3:1003:
smb2:1002:
3 新建用共享目錄
(1)新建目錄/samba作為共享目錄
[root@centos7 ~]# mkdir /samba
(2)修改共享目錄所屬組,由于Samba用戶都屬于centos組
[root@centos7 ~]# chgrp centos /samba/
(3)修改共享目錄的權限
[root@centos7 ~]# chmod 2770 /samba/
[root@centos7 ~]# ll /samba/ -d
drwxrwx— 2 root centos 6 Jun 7 16:24 /samba/
4 編輯Samba配置文件
(1)修改主配置文件/etc/samba/smb.conf
[root@centos7 ~]# vim /etc/samba/smb.conf
[global]
workgroup = MYGROUP ##工作組的名稱
security = user ##指定用戶通過密碼才能訪問
在最后添加如下幾行
[samba]
comment=My samba share ##只是這個目錄的說明而已
path=/samba ##共享的目錄
browseable=yes ##是否讓所有用戶看到這個項目
create mask = 0664 ##建立文件的權限
directory mask = 0775 ##建立目錄的權限
write list=@centos ##寫入者包括哪些人
(2)檢查配置文件語法
[root@centos7 ~]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section “[samba]”
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
# Global parameters
[samba]
comment = My samba share
path = /samba
create mask = 0664
directory mask = 0775
write list = @centos
5 啟動服務
[root@centos7 ~]# systemctl start smb.service
smbd主要功能就是管理Samba主機共享的目錄、文件與打印機
[root@centos7 ~]# systemctl start nmb.service
nmbd主要用來管理工作組、netBIOS name等的解析
二 客戶端配置
1 安裝所需軟件
[root@centos7 ~]# yum install samba-client samba-common -y
samba-client提供Samba客戶端所需的命令和工具,比如掛載文件格式的mount.cifs
2 使用smb1用戶登錄試試
[root@centos7 ~]# smbclient -L //192.168.29.130 -U smb1
Enter smb1’s password:
Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4] ##有時候OS=[Unix] 這個我也不知道為何
Sharename Type Comment
——— —- ——-
samba Disk My samba share
IPC$ IPC IPC Service (Samba 4.4.4)
Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]
3 掛載
(1)新建本地掛載目錄
[root@centos7 ~]# mkdir /smb/
(2)使用用戶smb1掛載
[root@centos7 ~]# mount -t cifs //192.168.29.130/samba /smb/ -o username=smb1,password=1234
(3)查看掛載
[root@centos7 ~]# df -h /smb
Filesystem Size Used Avail Use% Mounted on
//192.168.29.130/samba 10G 1.2G 8.9G 12% /smb
(4)設置開機掛載
[root@centos7 ~]# vim /etc/fstab
#
UUID=3ecec458-d4e7-4545-91bf-19cc36ce2ef7 / xfs defaults 0 0
UUID=b7dbdf8d-753a-441b-b9ad-99c261908427 /boot xfs defaults 0 0
UUID=05838299-1ad0-4e0b-a113-74ab99ed00f7 swap swap defaults 0 0
//192.168.29.130/samba /smb cifs defaults,username=smb1,password=1234 0 0
原創文章,作者:linux is not unix,如若轉載,請注明出處:http://www.www58058.com/78032