树莓派安装和配置samba服务器

  1. 安装samba服务器
sudo apt-get update
sudo apt-get install samba samba-common-bin
  1. 创建共享文件夹,更改文件夹权限
sudo mkdir /share
sudo chmod -R 777 /share
  1. 修改samba配置文件,添加共享文件夹的路径和属性
sudo vim /etc/samba/smb.conf

在文件最后面添加(将后面的注释去掉):

# ======================
[share]           #共享文件的名称, 将在网络上以此名称显示
 comment = Raspberry share folder
path = /share         #共享文件的路径
valid users = pi        #允许访问的用户
browseable = yes        #允许浏览
public = yes        #共享开放
writable = yes        #可写
  1. 使用testparm测试配置文件是否正确
testparm

如果执行成功则打印如下内容:

pi@raspberrypi:~ $ testparm 
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[print$]"
Processing section "[share]"
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

这里我第一次执行testparm的时候出现了错误,原因是samba配置文件中添加的内容包含非法字符,删除即可:


pi@raspberrypi:~ $ testparm
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[print$]"
Processing section "[share]"
set_variable_helper(true #允许浏览): value is not boolean!
Error loading services.
  1. 重启samba服务器
sudo service smbd restart
  1. 添加samba用户,这里的用户名要和前面配置文件中设置的用户名一致
sudo smbpasswd -a pi

之后需要输入两次密码,shell打印如下:

New SMB password:
Retype new SMB password:
Added user pi.
  1. 使用电脑连接samb服务器,连接前需要保证电脑和树莓派处于同一个局域网下
  • 在windows下使用windows+R组合键,在弹出的输入框中输入树莓派的ip地址
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sZbddenI-1622874256823)(652835BD39574EDA833EEACA5F5E2ACF)]

点击确定,成功即可访问共享文件夹[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IIPNE7OW-1622874256826)(4F602BEA8418467081B587A3EAEB86FE)]

猜你喜欢

转载自blog.csdn.net/weixin_39270987/article/details/117595020