- 一、安装Samba
首先查看是否安装Samba
[root@zml ~]# rpm -qa | grep samba
若没有,安装samba命令:
[root@zml ~]# yum install -y samba
- 二、关闭selinux和防火墙
[root@zml ~]# setenforce 0
[root@zml ~]# systemctl stop firewalld
[root@zml ~]# systemctl disable firewalld
- 三、配置Samba配置文件
备份配置文件
[root@zml ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
修改 /etc/samba/smb.conf配置文件
[root@zml ~]# vi /etc/samba/smb.conf
添加共享文件信息
[share] # 共享文件夹的名称
comment = myshare #描述
path= /home/share # 路径
writable = yes # 是否可写入
public = no # 是否公开
- 四、添加用户账号(如上配置中添加的内容)
- [root@zml ~]# useradd -d /home/share -s /sbin/nologin share
- 将share添加为samba用户
- [root@zml ~]# pdbedit -a -u share
- 五、修改samba用户的/home/share目录权限
[root@zml ~]# chown -Rf share:share /home/share
六、启动samba服务
[root@zml ~]# systemctl start smb
[root@zml ~]# systemctl enable smb
[root@zml ~]# systemctl restart smb
[root@zml ~]# systemctl status smb
- 七、在共享路径/home/share里添加点测试文档
[root@zml ~]# cd /home/share
[root@zml share]# touch test{1..5}.txt
[root@zml share]# mkdir test
[root@zml share]# ls
test test1.txt test2.txt test3.txt test4.txt test5.txt
- 八、测试
- 将samba共享目录挂载到windows上,右键“此电脑”选择“映射网络驱动器”
- 输入\\ip地址\共享文件夹名
连接成功。