邢台市刚刚发生的事seo运营
公司内部需要文件共享,自建samba服务,满足功能
在搭建过程中,踩了一些坑,如windows无法访问、macos无法访问、账号添加、权限控制
分享一下实现过程,内容不详细的地方,可评论或私聊
前置准备
服务器 阿里云/centos7.9
客户端 windows10、windows11、macos、centos
工具 samba samba-client
yum -y install samba samba-client
搭建samba服务
服务配置
vim /etc/samba/smb.conf
[global]workgroup = SAMBAsecurity = userpassdb backend = tdbsamprinting = cupsprintcap name = cupsload printers = yescups options = rawmap to guest = Bad Userpassdb backend = tdbsamsmb ports = 6727[homes]comment = Home Directoriesvalid users = %S, %D%w%Sbrowseable = Noread only = Noinherit acls = Yes[printers]comment = All Printerspath = /var/tmpprintable = Yescreate mask = 0600browseable = No[print$]comment = Printer Driverspath = /var/lib/samba/driverswrite list = @printadmin rootforce group = @printadmincreate mask = 0664directory mask = 0775
[share]path = /opt/abcpublic = nobrowseable = yeswritable = yescreate mask = 0777directory mask = 0777valid users = tom,bobo
添加用户
adduser tom
smbpasswd -a tom
启动服务
# 启动
systemctl start smb
# 停止
systemctl stop smb
# 重启
systemctl restart smb
根据配置 smb ports = 6727,需要服务器开放6727端口
为什么修改smb默认445端口,可参考 https://www.jianshu.com/p/6658e3b5a74a
windows连接
连接配置
- 使用管理员权限运行cmd
- 执行以下命令
# 关闭LanmanServer服务
sc config LanmanServer start=disabled
net stop LanmanServer
# 启动ip helper服务,用于接口转发
sc config iphlpsvc start=auto
# 设置端口转发
netsh interface portproxy add v4tov4 listenport=445 connectaddress=xxx.xx.xx.xx connectport=6727
查看转发的端口
netsh interface portproxy show v4tov4
显示如下,说明成功
全部执行完成后,重启电脑
使用
输入\127.0.0.1\share访问
另外一种方式
macos
打开访达
centos
命令连接
smbclient //xxx.xx.xx.xx/share -p6727 -U username
有使用问题,可评论或私聊
参考资料
windows如何访问公网samba
samba安装和配置