1.配置用户认证共享:
1.在服务端上安装samba服务:
[root@ye ~]# yum -y install samba-*
2.创建用户one,为one用户创建smb共享密码:
[root@ye ~]# useradd -M one
[root@ye ~]# smbpasswd -a one
New SMB password:
Retype new SMB password:
Added user one.
3.在全局配置中添加如下内容:
[root@ye ~]# vim /etc/samba/smb.conf
[root@ye ~]# cat /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA
security = user
username map = /etc/samba/user //添加此行内容
4.创建一个共享目录
[root@ye ~]# mkdir /ye
[root@ye ~]# chown one.one /ye
5.假设这里映射one用户为aaa用户,那么就要在/etc/samba下创建文件user,在其中添加如下内容:
[root@ye ~]# cd /etc/samba/
[root@ye samba]# vim user
[root@ye samba]# cat user
one = aaa
6.配置共享:
[root@ye ~]# vim /etc/samba/smb.conf
在最下面添加:
[one]
comment = one
path = /ye
browseable = yes
guest ok = yes
writable = yes
write list = aaa
public = yes
重启smb服务:
[root@ye ~]# systemctl restart smb
7.关闭防火墙与selinux:
[root@ye ~]# systemctl stop firewalld
[root@ye ~]# setenforce 0
8.在客户端上验证:
在客户机安装samba-client包:
[root@peng ~]# yum -y install samba-client
查看samba服务器有哪些共享资源
[root@peng ~]# smbclient -L 192.168.47.137 -U aaa
Enter SAMBA\aaa's password:
Domain=[YE] OS=[Windows 6.1] Server=[Samba 4.6.2]
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
one Disk one
IPC$ IPC IPC Service (Samba 4.6.2)
Domain=[YE] OS=[Windows 6.1] Server=[Samba 4.6.2]
Server Comment
--------- -------
Workgroup Master
--------- -------
挂载到本地目录opt下
[root@peng ~]# mount -t cifs -o username=one,password=qwe //192.168.47.137/one /opt/
[root@peng ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/rhel-root 17G 995M 17G 6% /
devtmpfs 901M 0 901M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.6M 904M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 143M 872M 15% /boot
tmpfs 183M 0 183M 0% /run/user/0
/dev/sr0 3.8G 3.8G 0 100% /mnt
//192.168.47.137/one 17G 1.2G 16G 7% /opt
进入目录opt,并创建文件
[root@peng opt]# touch 12
[root@peng opt]# ll
总用量 0
-rw-r--r--. 1 1000 1000 0 1月 15 15:33 12
9.返回服务端查看:配置成功
[root@ye ~]# ll /ye/
total 0
-rw-r--r--. 1 one one 0 Jan 15 02:33 12
2. 配置匿名共享:
1.在服务端上安装samba服务:
[root@ye ~]# yum -y install samba-*
2.在全局配置中添加如下内容:
[root@ye ~]# vim /etc/samba/smb.conf
[root@ye ~]# cat /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA
security = user
map to guest = Bad User //添加此行内容
3.创建一个共享目录
[root@ye ~]# mkdir /peng
[root@ye ~]# chmod 777 /peng/
[root@ye ~]# ll /peng/ -d
drwxrwxrwx. 2 root root 6 Jan 15 03:32 /peng/
[root@ye ~]#
4.配置共享
[root@ye ~]# vim /etc/samba/smb.conf
在最下面添加:
[peng]
comment = tow
path = /peng
browseable = yes
guest ok = yes
writable = yes
public = yes
5.重启smb服务,关闭防火墙与selinux:
[root@ye ~]# systemctl restart smb
[root@ye ~]# systemctl stop firewalld
[root@ye ~]# setenforce 0
6.在客户机查看samba服务器有哪些共享资源:
[root@peng ~]# smbclient -L 192.168.47.137 -U 'Bad User'
Enter SAMBA\Bad User's password:
OS=[Windows 6.1] Server=[Samba 4.6.2]
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
peng Disk tow
IPC$ IPC IPC Service (Samba 4.6.2)
OS=[Windows 6.1] Server=[Samba 4.6.2]
Server Comment
--------- -------
Workgroup Master
--------- -------
7.将samba服务器的共享资源peng挂载到客户机本地:
[root@peng ~]# mount -t cifs -o username='Bad User' //192.168.47.137/peng /opt/
[root@peng ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/rhel-root 17G 995M 17G 6% /
devtmpfs 901M 0 901M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.6M 904M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 143M 872M 15% /boot
tmpfs 183M 0 183M 0% /run/user/0
//192.168.47.137/peng 17G 1.2G 16G 7% /opt
8.在客户机上进入共享目录创建新文件
[root@peng ~]# cd /opt/
[root@peng opt]# ls
[root@peng opt]#
[root@peng opt]# touch qq
[root@peng opt]# ll
总用量 0
-rw-r--r--. 1 nobody nobody 0 1月 15 17:10 qq
9.到服务端上查看:配置成功
[root@ye ~]# ll /peng/
total 0
-rw-r--r--. 1 nobody nobody 0 Jan 15 04:10 qq
Samba服务:
在server上配置SAMBA服务
您的samba服务器必须是STAFF工作组的一个成员
共享/common目录,共享名为common
只有example.com域内的客户端可以访问common共享
common 必须是可以浏览的
用户natasha必须能够读取共享中的内容,如果需要的话,验证密码是:tangkai
在服务端上安装samba服务:
[root@server30 ~]# yum -y install samba*
修改工作组:
[root@server30 ~]# cd /etc/samba/
[root@server30 samba]# vim smb.conf
找到下面这个并修改:
workgroup = STAFF
创建目录/common
[root@server30 ~]# mkdir /common
添加防火墙规则:
[root@server30 ~]# systemctl mask iptables.service ebtables.service
[root@server30 ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=172.16.30.0/24 service name=samba accept' --permanent
success
[root@server30 ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=172.16.30.0/24 service name=samba-client accept' --permanent
success
[root@server30 ~]# firewall-cmd --reload
success
创建用户natasha,为natasha用户创建smb共享密码
[root@server30 ~]# useradd natasha
[root@server30 ~]# smbpasswd -a natasha
配置共享:
[root@server30 ~]# vim /etc/samba/smb.conf
[common]
path = /common
browseable = yes
valid users = natasha
设置acl:
[root@server30 ~]# setfacl -m u:natasha:r-x /common
添加selinux:
[root@server30 ~]# setsebool -P samba_enable_home_dirs on
设置samba服务开机自启,并重启:
[root@server30 ~]# systemctl enable smb nmb
[root@server30 ~]# systemctl restart smb nmb
为/common设置上下文切换:
[root@server30 ~]# chcon -Rt samba_share_t /common
将samba服务器的共享资源common挂载到客户机本地:
[root@desktop30 ~]# mount -t cifs -o username=natasha,password=tangkai //172.16.30.100/common /mnt
[root@desktop30 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 4.9G 2.9G 2.0G 60% /
devtmpfs 985M 0 985M 0% /dev
tmpfs 994M 140K 994M 1% /dev/shm
tmpfs 994M 8.8M 986M 1% /run
tmpfs 994M 0 994M 0% /sys/fs/cgroup
/dev/sda1 197M 104M 94M 53% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
//172.16.30.100/common 4.9G 3.0G 2.0G 60% /mnt
验证:
在服务端下的/common中创建文件aa
[root@server30 ~]# cd /common/
[root@server30 common]# touch aa
在客户端上查看
[root@desktop30 ~]# cd /common
[root@desktop30 mnt]# ls
aa
多用户samba挂载:
在server上通过samba共享目录/storage
共享名为share
共享目录只能被example.com域内的客户端使用
共享目录share必须可以被浏览
用户sarah能以读的方式访问此共享,访问密码是tangkai
用户sarah能读的方式访问此共享,访问密码是tangkai
用户kitty能读写的方式访问此共享,访问密码是tangkai
此目录永久挂载在desktop上的/mnt/dev/目录,并使用用户sarah进行认证。任何用户可临时通过kitty来获得读写权限
在服务端上:
创建目录/storage,并设置上下文切换
[root@server30 ~]# mkdir /storage
[root@server30 ~]# chcon -Rt samba_share_t /storage
配置共享:
[root@server30 ~]# vim /etc/samba/smb.conf
在最下面添加
[share]
path = /storage
browseable = yes
valid users = sarah,kitty
writable = no
write list = kitty
重启samba服务:
[root@server30 ~]# systemctl restart smb nmb
创建用户sarah,kitty,并创建smb共享密码,密码为tangkai
[root@server30 ~]# useradd sarah
[root@server30 ~]# useradd kitty
[root@server30 ~]# smbpasswd -a sarah
[root@server30 ~]# smbpasswd -a kitty
添加acl:
[root@server30 ~]# setfacl -m u:sarah:r-x /storage
[root@server30 ~]# setfacl -m u:kitty:rwx /storage
在客户端上:
取消挂载:
[root@desktop30 ~]# umount /mnt
创建目录:
[root@desktop30 ~]# mkdir /mnt/dev
将samba服务器的共享资源common挂载到客户机本地
[root@desktop30 ~]# vim /etc/fstab
//172.16.30.100/share /mnt/dev/ cifs multiuser,username=sarah,password=tangkai,sec=ntlmssp 0 0
进入目录/dev,不能创建文件,是对的
[root@desktop30 ~]# cd /mnt/dev
[root@desktop30 dev]# touch 11
touch: cannot touch ‘11’: Permission denied
验证:
安装cifs服务:
[root@desktop30 ~]# yum -y install cifs-utils*
查看一下home下的普通用户,并进行登陆:
[root@desktop30 ~]# ls /home/
student
[root@desktop30 ~]# su - student
然后在切换到用户kitty,进行验证:配置成功
[student@desktop30 ~]$ cifscreds add -u kitty 172.16.30.100
Password:
[student@desktop30 ~]$ cd /mnt/dev/
[student@desktop30 dev]$ touch aa
[student@desktop30 dev]$ ll
total 0
-rw-r--r--. 1 1003 1003 0 Jan 15 19:50 aa