这两天学习linux的samba文件共享,创建过程有些坑,这里记录一下以便其他后来者避坑。
以下为记录说明
首先安装samba应用 :yum -y install samba-client
然后启动samba服务: systemctl start smb nmb
接下来修改samba配置文件 vi /etc/samba/smb.conf
文件其它内容不管,直接在末尾添加: //注释不需要写入
[samba_share] //共享后从其他客户端查看到的目录名
comment = Centos share //随意命名
path = /samba_share //共享的centos路径
browseable = yes //共享指定路径可浏览
writable = yes //共享指定路径可写
valid users =smbtest //共享允许访问的用户
保存并退出。
重启smb服务:systemctl restart smb.service
重启nmb服务:systemctl restart nmb.service
共享的目录为新文件,需要新创建:mkdir /samba_share
修改文件夹访问权限: chmod 777 /samba_share
权限最好是777,要不然后面可能会出现访问不了的情况,当然也可以自己定义
此时创建smb用户:
[root@localhost /]# smbpasswd -a smbtest
New SMB password:
Retype new SMB password:
Failed to add entry for user smbtest.
发现会提示创建错误,后来发现是因为 smbtest用户不是centos用户,需先添加smbtest
[root@localhost samba_share]# useradd smbtest
[root@localhost samba_share]# passwd smbtest
更改用户 smbtest 的密码 。
新的 密码:
无效的密码: 密码未通过字典检查 - 过于简单化/系统化
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
创建用户后再添加到smb用户中
[root@localhost samba_share]# smbpasswd -a smbtest
New SMB password:
Retype new SMB password:
Added user smbtest.
添加成功。
windows电脑 ‘win+R’ 输入 ‘\\[ip]’例如 \\192.168.0.108
输入完成确定,在弹窗中输入创建的smb用户smbtest和设置的密码即可进行连接。
连接成功后尝试在pc端建立文件然后再centos查看是否成功。
若windows一直提示连接不成功,可能需要关闭centos防火墙再试
关闭防火墙:
[root@localhost samba_share]# setenforce 0
[root@localhost samba_share]# systemctl stop firewalld