建立samba共享

数据目录为 /data

1)共享名为shared,工作组为whmall

vim /etc/samba/smb.conf

1
2
3
4
5
6
7
8
9
10
修改
workgroup = MYGROUP

workgroup = whmall

修改
passdb backend = tdbsam

passdb backend = smbpasswd
smb passwd file = /etc/samba/smbpasswd

2)添加组develop,添加用户gentoo,centos和ubuntu,其中gentoo和centos以develop为附加组,ubuntu不属于develop组;密码均为用户名

1
2
3
4
5
6
7
8
9
10
11
[root@CentOS7 samba]# groupadd develop
[root@CentOS7 samba]# useradd -G develop gentoo
[root@CentOS7 samba]# useradd -G develop centos
[root@CentOS7 samba]# useradd ubuntu
[root@CentOS7 samba]# echo "gentoo"| passwd --stdin gentoo
更改用户 gentoo 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@CentOS7 samba]# echo "centos"| passwd --stdin centos
更改用户 centos 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@CentOS7 samba]# echo "ubuntu"| passwd --stdin ubuntu

3)添加samba用户gentoo,centos和ubuntu,密码均为“111111”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@CentOS7 samba]#  smbpasswd -a gentoo
New SMB password:
Retype new SMB password:
startsmbfilepwent_internal: file /etc/samba/smbpasswd did not exist. File successfully created.
Added user gentoo.
[root@CentOS7 samba]# smbpasswd -a centos
New SMB password:
Retype new SMB password:
Added user centos.
[root@CentOS7 samba]# smbpasswd -a ubuntu
New SMB password:
Retype new SMB password:
Added user ubuntu.
[root@CentOS7 samba]#

4)此samba共享shared仅允许develop组具有写权限,其他用户只能以只读方式访问

vim smb.conf

1
2
3
4
5
6
7
末尾添加
[shared]
comment = whmall.com
path = /data
guest = yes
writable = no
write list = +develop

5)此samba共享服务仅允许来自于172.16.0.0/16网络的主机访问;

vim smb.conf

1
2
添加 
hosts allow = 172.16.0.0/16

启动samba服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@CentOS7 samba]# systemctl start smb.service
[root@CentOS7 samba]# systemctl status smb.service
● smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled)
Active: active (running) since 四 2017-03-23 14:39:18 CST; 5s ago
Main PID: 101560 (smbd)
Status: "smbd: ready to serve connections..."
CGroup: /system.slice/smb.service
├─101560 /usr/sbin/smbd
├─101561 /usr/sbin/smbd
├─101562 /usr/sbin/smbd
└─101563 /usr/sbin/smbd

3月 23 14:39:18 CentOS7 systemd[1]: Starting Samba SMB Daemon...
3月 23 14:39:18 CentOS7 smbd[101557]: [2017/03/23 14:39:18.773050, 0] .....)
3月 23 14:39:18 CentOS7 smbd[101557]: Unknown parameter encountered: "g..."
3月 23 14:39:18 CentOS7 smbd[101557]: [2017/03/23 14:39:18.773117, 0] .....)
3月 23 14:39:18 CentOS7 smbd[101557]: Ignoring unknown parameter "guest"
3月 23 14:39:18 CentOS7 systemd[1]: smb.service: Supervising process 101...s.
3月 23 14:39:18 CentOS7 smbd[101560]: [2017/03/23 14:39:18.787425, 0] .....)
3月 23 14:39:18 CentOS7 smbd[101560]: STATUS=daemon 'smbd' finished sta...s
3月 23 14:39:18 CentOS7 systemd[1]: Started Samba SMB Daemon.
Hint: Some lines were ellipsized, use -l to show in full.

PS: CentOS7最好关闭防火墙,还有SELinux

1
2
3
4
5
6
[root@CentOS7 ~]# systemctl list-unit-files |grep fire
firewalld.service enabled
[root@CentOS7 ~]# systemctl stop firewalld.service
[root@CentOS7 ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

亲测OK,有图有真相

PS:这里我把hosts allow = 172.16.0.0/16 改为了hosts allow = 192.168.0.0/24

workgroup 改为WORKGROUP

这样就看到了,欧耶~

0%