samba服务
实验环境
主机名 | IP地址 | 角色 |
---|---|---|
samba-server | 192.168.100.33 | 服务端 |
samba-client | 192.168.100.60 | 客户端 |
- 关闭服务端的防火墙和selinux
[root@samba-server ~]# systemctl stop firewalld.service
[root@samba-server ~]# systemctl disable firewalld.service
[root@samba-server ~]# setenforce 0
- 安装samba
[root@samba-server ~]# yum -y install samba-* //服务端
[root@samba-client ~]# yum -y install samba-client //客户端
- 启动服务,并加入到开机自启
[root@samba-server ~]# systemctl start smb
[root@samba-server ~]# systemctl enable smb
实验一
搭建匿名用户共享服务器
服务端配置
- 新建共享目录,设置权限
[root@samba-server ~]# mkdir /date/samba/shard -p
[root@samba-server ~]# chmod 777 /date/samba/shard/ -R
- 修改/etc/samba/smb.conf的配置文件
[root@samba-server ~]# 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 //匿名用户 虚拟的
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[samba-shard]
comment = This is shard //说明信息
path = /date/samba/shard //共享文件的路径
browseable = yes //共享文件可见
guest ok =yes //所有人均可访问共享
writable = yes //读写权限
public = yes //开启匿名访问
- 检测配置文件是否修改有误
[root@samba-server ~]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[samba-shard]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
- 重启服务
[root@samba-server ~]# systemctl restart smb
客户端检测
- 查看共享目录
[root@samba-client ~]# smbclient -L 192.168.100.33 -U 'Bad user' //不用输入密码,直接回车
- 挂载
[root@samba-client /]# mkdir /cifs //建立挂载点
[root@samba-client /]# mount -t cifs //192.168.100.33/samba-shard /cifs/ -o user="Bad User" //不用输入密码 直接回车
- 检测
[root@samba-client cifs]# mkdir xiefei //客户端有写入权限
[root@samba-server ~]# ls /date/samba/shard/
xiefei
搭建用户认证共享服务器,需要映射系统用户为虚拟用户
服务端配置
- 新建samba用户
[root@samba-server ~]# useradd jerry -s /sbin/nologin
[root@samba-server ~]# smbpasswd -a jerry
- 新建共享目录,赋予权限
[root@samba-server ~]# mkdir /date/samba/share -p
[root@samba-server ~]# chown jerry.jerry /date/samba/share -R
- 修改配置文件,在/etc/samba/smb.conf的配置文件最下面添加
[root@samba-server ~]# cat /etc/samba/smb.conf
[samba-share]
comment = This is share
path = /date/samba/share
public = no
writable = yes
- 映射系统用户,并将路径写入smb.conf配置中
[root@samba-server ~]# echo "jerry = dingxiaoke" > /etc/samba/smbusers //将系统用户jerry映射为dingxiaoke虚拟用户
[root@samba-server ~]# cat //etc/samba/smb.conf
[global]
workgroup = SAMBA
security = user
map to guest = Bad User
username map = /etc/samba/smbusers
passdb backend = tdbsam
- 重启服务
[root@samba-server ~]# systemctl restart smb.service
客户端验证
- 查看共享目录
[root@samba-client cifs]# smbclient -L 192.168.100.33 -U dingxiaoke //需要输入密码
Enter SAMBA\dingxiaoke's password:
Sharename Type Comment
--------- ---- -------
samba-shard Disk This is shard
samba-share Disk This is share
IPC$ IPC IPC Service (Samba 4.7.1)
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
- 挂载
[root@samba-client cifs]# mkdir /samba -p
[root@samba-client cifs]# mount -t cifs -o user=dingxiaoke,pass=123.com //192.168.100.33/samba-share /samba/
- 检测
[root@samba-client samba]# echo "xiefei.com" >> 123 //客户端创建
[root@samba-client samba]# ls
123
[root@samba-server ~]# cat /date/samba/share/123 //服务验证该用户有读写权限
xiefei.com
- 自动挂载
[root@samba-client samba]# vim /etc/fstab
//192.168.100.33/samba-share /samba cifs defaults,_netdev,user=dingxiaoke,pass=123.com 0 0
- 检测
[root@samba-client ~]# mount -a
[root@samba-client ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 8897536 1594224 7303312 18% /
devtmpfs 490012 0 490012 0% /dev
tmpfs 499860 0 499860 0% /dev/shm
tmpfs 499860 6880 492980 2% /run
tmpfs 499860 0 499860 0% /sys/fs/cgroup
/dev/sda1 1038336 121688 916648 12% /boot
tmpfs 99972 0 99972 0% /run/user/0
//192.168.100.33/samba-shard 19383296 3280504 16102792 17% /cifs
//192.168.100.33/samba-share 19383296 3280504 16102792 17% /samba //挂载成功