1. 搭建用户认证共享服务器
1.1 安装服务
[root@liuwei liuwei]# yum -y install samba*
1.2 配置全局变量
[root@liuwei liuwei]# head /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
1.3 创建一个共享目录
[root@liuwei liuwei]# mkdir /liuwei
[root@liuwei liuwei]# chown liuwei.liuwei /liuwei
[root@liuwei liuwei]# ll /liuwei -d
drwxr-xr-x. 3 liuwei liuwei 40 1月 15 08:58 /liuwei
1.4 配置共享
[root@liuwei liuwei]# tail /etc/samba/smb.conf
force group = @printadmin
create mask = 0664
[liuwei]
path = /liuwei
browseable = yes
guest ok = yes
writable =yes
write list = lw
public = yes
1.5 开启smb服务
[root@liuwei liuwei]# systemctl start smb
[root@liuwei liuwei]# systemctl restart smb
[root@liuwei liuwei]# systemctl enable smb
[root@liuwei liuwei]# systemctl reload smb
1.6 关闭防火墙
[root@liuwei liuwei]# systemctl stop firewalld
[root@liuwei liuwei]# setenforce 0
1.7 客户机查看资源
[root@lw smb]# smbclient -L 192.168.110.21 -U lw
Enter SAMBA\lw's password:
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
liuwei Disk
IPC$ IPC IPC Service (Samba 4.8.3)
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
SAMBA LIUWEI
1.8 挂载samba服务器到客户端
[root@lw ~]# mount -t cifs -o username=lw,password=1 //192.168.110.21/liuwei /opt/smb/
[root@lw ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/rhel-root 18G 1.7G 16G 10% /
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 497M 136M 362M 28% /boot
tmpfs 183M 0 183M 0% /run/user/0
//192.168.110.21/liuwei 8.0G 1.3G 6.8G 16% /opt/smb
1.9 客户机验证
客户机:
[root@lw smb]# ls
[root@lw smb]# touch aa
[root@lw smb]# ll
总用量 0
-rw-r--r--. 1 996 993 0 1月 15 09:24 aa
服务器:
[root@liuwei liuwei]# ll
总用量 0
-rw-r--r--. 1 liuwei liuwei 0 1月 15 09:24 aa
drwxr-xr-x. 2 liuwei liuwei 6 1月 15 09:26 新建文件夹
注释:
linux客户机:192.168.110.21
Windows客户机
linux服务器:192.168.110.20
共享用户:liuwei
映射用户:lw
共享目录:/liuwei
共享目录密码:1
2.搭建匿名用户共享服务器
2.1 安装Samba服务
[root@liuwei liuwei]# yum -y install samba*
2.2 配置全局变量
[root@lw smb]# vim /etc/samba/smb.conf
[root@lw smb]# head /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
2.3 配置共享目录
[root@lw smb]# mkdir /liuwei
[root@lw smb]# chmod 777 /liuwei/
[root@lw smb]# ll /liuwei/ -d
drwxrwxrwx. 2 root root 6 1月 15 09:32 /liuwei/
2.4 配置共享
[root@lw smb]# vim /etc/samba/smb.conf
[root@lw smb]# tail -6 /etc/samba/smb.conf
[liuwei]
path = /liuwei
browseable = yes
guest ok =yes
writable =yes
public = yes
2.5 开启Samba服务
[root@lw smb]# systemctl start smb
[root@lw smb]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
2.6 关闭防火墙
[root@lw liuwei]# systemctl stop firewalld
[root@lw liuwei]# setenforce 0
2.7 客户机查看资源
[root@liuwei ~]# smbclient -L 192.168.110.20 -U 'Bad User'
Enter SAMBA\Bad User's password:
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
liuwei Disk
IPC$ IPC IPC Service (Samba 4.8.3)
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
SAMBA LW
2.8 挂载samba服务器
[root@liuwei ~]# smbclient -L 192.168.110.20 -U 'Bad User'
Enter SAMBA\Bad User's password:
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
liuwei Disk
IPC$ IPC IPC Service (Samba 4.8.3)
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
SAMBA LW
2.9 验证客户机
客户端:
[root@liuwei ~]# cd /opt/smb/
[root@liuwei smb]# touch 123
[root@liuwei smb]# ls
123
[root@liuwei smb]# ll
总用量 0
-rw-r--r--. 1 nobody nobody 0 1月 15 09:56 123
服务端:
[root@lw smb]# cd /liuwei/
[root@lw liuwei]# ll
总用量 0
-rw-r--r--. 1 nobody nobody 0 1月 15 09:56 123
drwxr-xr-x. 2 nobody nobody 6 1月 15 09:57 新建文件夹
注释:
linux客户机:192.168.110.21
windows客户机
linux服务器:192.168.110.20
共享目录:/liuwei
RHCE中samba试题
题目:
修改工作组成员
workgroup = STAFF
设置共享目录
[common]
path = /common
browseable = yes
设置防火墙规则
[root@server30 ~]# mkdir /common
[root@server30 ~]# systemctl mask iptables.service ebtables.service
ln -s '/dev/null' '/etc/systemd/system/iptables.service'
ln -s '/dev/null' '/etc/systemd/system/ebtables.service'
[root@server30 ~]# systemctl start firewalld
[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
设置用户
[root@server30 ~]# useradd natasha
[root@server30 ~]# smbpasswd -a natasha
New SMB password:
Retype new SMB password:
Added user natasha.
[root@server30 ~]# setfacl -m u:natasha:r-x /common/
设置selinux
[root@server30 ~]# setsebool -P samba_enable_home_dirs on
[root@server30 ~]# getsebool -a |grep samba |grep dirs
samba_create_home_dirs --> off
samba_enable_home_dirs --> on
use_samba_home_dirs --> off
设置samba
[root@server30 ~]# chcon -Rt samba_share_t /common
[root@server30 ~]# systemctl start smb nmb
[root@server30 ~]# systemctl enable smb nmb
ln -s '/usr/lib/systemd/system/smb.service' '/etc/systemd/system/multi-user.target.wants/smb.service'
ln -s '/usr/lib/systemd/system/nmb.service' '/etc/systemd/system/multi-user.target.wants/nmb.service'
[root@server30 ~]# systemctl restart smb nmb
客户端挂载samba
[root@desktop30 ~]# mount -t cifs -o username=natasha,password=tangkai //172.16.30.130/common /mnt
[root@desktop30 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 4.9G 3.0G 2.0G 60% /
devtmpfs 481M 0 481M 0% /dev
tmpfs 490M 0 490M 0% /dev/shm
tmpfs 490M 13M 478M 3% /run
tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/sda1 197M 91M 107M 46% /boot
//172.16.30.130/common 4.9G 3.0G 2.0G 61% /mnt
设置共享目录
[root@server30 common]# mkdir /storage
[root@server30 common]# chcon -Rt samba_share_t /storage/
设置samba
[share]
path = /storage
browseable = yes
valid users = sarah,kitty
writable = no
write list = kitty
设置用户与密码
[root@server30 common]# useradd sarah
[root@server30 common]# useradd kitty
[root@server30 common]# smbpasswd -a sarah
New SMB password:
Retype new SMB password:
Added user sarah.
[root@server30 common]# smbpasswd -a kitty
New SMB password:
Retype new SMB password:
Added user kitty.
[root@server30 common]# setfacl -m u:sarah:r-x /storage/
[root@server30 common]# setfacl -m u:kitty:rwx /storage/
多用户挂载
[root@desktop30 ~]# mkdir /mnt/dev
[root@desktop30 ~]# vim /etc/fstab
//172.16.30.130/share /mnt/dev cifs multiuser,uaername=sarah,password=tangkai,sec=ntlmssp 0 0
[root@desktop30 mnt]# mount -a
[root@desktop30 mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 4.9G 3.0G 2.0G 61% /
devtmpfs 481M 0 481M 0% /dev
tmpfs 490M 80K 490M 1% /dev/shm
tmpfs 490M 7.0M 484M 2% /run
tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/sda1 197M 91M 107M 46% /boot
//172.16.30.130/share 4.9G 3.0G 2.0G 61% /mnt/dev
[root@desktop30 dev]# yum -y install cifs-utils*
[student@desktop30 dev]$ cifscreds add -u kitty 172.16.30.130
Password:
[student@desktop30 ~]$ cd /mnt/dev/
[student@desktop30 dev]$ touch 123