关于samba
Samba是一个实现不同操作系统(Windows、Linux、UNIX)之间文件共享和打印机共享的一种
SMB协议的免费软件。SMB协议是客户机/服务器协议,客户机通过该协议可以访问服务器上的共享
文件及打印机共享资源。它主要应用于局域网上,也可以通过设置“NetBIOS over TCP/IP”同互
联网中的电脑分享资源。
一.samba服务的配置
在sam服务端
[root@shareserver ~]# yum install -y samba samba-client samba-common
samba 提供samba服务的主命令;
samba-common 提供管理命令;
samba-client 提供测试服务
[root@shareserver ~]# systemctl start smb
[root@shareserver ~]# netstat -antlp | grep smb # 查看samba的端口
[root@shareserver ~]# id student # 查看本机用户
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)
[root@shareserver ~]# id linux
uid=1002(linux) gid=1002(linux) groups=1002(linux)
[root@shareserver ~]# smbpasswd -a linux # 把本机用户添加到sam服务器上
New SMB password: # 设置samba用户的密码,此密码与本机用户的密码无关
Retype new SMB password:
Added user linux.
[root@shareserver ~]# smbpasswd -a student
New SMB password:
Retype new SMB password:
Added user student.
[root@shareserver ~]# pdbedit -L # 查看smb中的所有用户
linux:1002:
student:1000:student
[root@shareserver ~]# pdbedit -x student # 删除amb中的student用户
[root@shareserver ~]# pdbedit -L
linux:1002:
在客户端测试
[root@client ~]# yum install -y samba-client
[root@client ~]# smbclient -L //172.25.254.142/linux -U linux # 发现不能查看 ,这可能是因为火墙阻挡了客户端的访问
在服务端关闭火墙
[root@shareserver ~]# systemctl stop firewalld
在客户端
[root@client ~]# smbclient -L //172.25.254.142 # 匿名登陆服务端,并查看信息,-L表示查看共享列表
[root@client ~]# smbclient -L //172.25.254.142 -U linux # 指定linux用户登陆,-U表示指定用户
[root@client ~]# smbclient //172.25.254.142/linux -U linux # 登陆共享服务端,查看共享用户的家目录信息时发现被拒绝
在服务端排错
[root@shareserver ~]# getenforce # selinux与samba服务冲突
Enforcing
[root@shareserver ~]# getsebool -a | grep samba
[root@shareserver ~]# setsebool -P samba_enable_home_dirs on # 分享home目录即可·
在客户端
[root@client ~]# smbclient //172.25.254.142/linux -U linux
[root@client ~]# mount -o username=linux,password=linux //172.25.254.142/linux /mnt # 把用户挂载到/mnt下,方便对共享用户进行管理
[root@client ~]# df
[root@client ~]# cd /mnt
[root@client mnt]# touch file{1..3}
在服务端Linux用户家目录查看
[root@shareserver ~]# cd /home/linux/
[root@shareserver linux]# ls
file1 file2 file3 linuxfile
二.samba的访问控制
1.域名的修改
在客户端
[root@client mnt]# smbclient -L //172.25.254.142/linux -U linux # 查看到域名为MYGROUP
在服务端修改域名
[root@shareserver ~]# vim /etc/samba/smb.conf
89 workgroup = LINUX[
root@shareserver ~]# systemctl restart smb.service
在客户端
[root@client mnt]# smbclient -L //172.25.254.142/linux -U linux # 再次查看,域名修改成功