树莓派设置samba文件共享

前序文章:

这是折腾树莓派的第四篇文章,主要讲解如何设置samba文件共享,当做家庭nas。

samba介绍

samba是unix/linux系统与windows操作系统进行文件和打印机共享的网络协议。因其设置简单使用方便,在内网环境中十分受欢迎,可以认为是内网版的ftp。

windows、macos以及许多桌面版的linux系统直接继承samba客户端,可方便的添加和卸载samba网盘。

树莓派安装和设置samba

本节介绍在树莓派上安装和设置samba,其操作步骤为:

1. 安装samba软件

安装命令:

sudo apt update && sudo apt upgrade && sudo apt-get install -y samba

2. 设置samba

samba的配置文件是/etc/samba/smb.conf,其配置主要包含四部分:

  1. global:samba软件的全局设置;
  2. homes:系统用户主目录共享设置,默认用户才能访问自己的主目录;
  3. printers:共享打印机设置
  4. 用户自定义的共享目录设置

前三部分可根据自己的需求更改,也可保持默认(如有不懂请man 5 smb.conf查看字段含义)。下文针对公共共享目录自定义私有目录两方面解释自定义共享目录操作的步骤。

  1. 公共共享目录。在/etc/samba/smb.conf末尾增加类似如下配置(#号开头部分是说明):
    # 配置段名称,可以随意取
    [public]
    # 共享段备注
    comment = public folder
    # 共享文件夹路径,必填
    path = /public
    # 允许可以写入
    read only = no
    # 允许匿名访问
    public = yes
    # 是否出现在网络发现中
    browseable = yes
  2. 自定义共享目录,增加配置如下:
    [tlanyan]
    comment = tlanyan windows file
    path = /mnt/tlanyan
    # 不出现在网络发现中
    browseable = no
    # 禁止匿名访问
    public = no
    writable = yes
    # 只允许pi用户访问
    valid users = pi

配置完成后,sudo systemctl restart smbd重启samba服务。

3. 客户端连接

由于windows和macos内置了对samba协议的支持,访问samba文件夹是非常方便的。

windows: 打开“我的电脑”,点击上方菜单栏的“添加网络驱动器”,在弹出来的窗口中点击“选择自定义网络位置”,接着输入“//ip/文件夹名称”,按照引导完成连接设置;
树莓派设置samba文件共享

macos:打开finder -> 前往 -> 连接服务器,在弹框中输入”smb://ip/共享文件夹”:
树莓派设置samba文件共享

如果设置了访问权限,根据提示输入用户名和密码。正确无误的话,在系统中便可以看到挂在的共享文件夹。设置了写权限的共享文件夹可以当作本地磁盘来用,操作上完全一致,并且由于一般在内网,速度上也不会感觉有延迟。

其它

  1. 树莓派默认的存储只有一个sd卡,你需要通过usb外接硬盘才能很好的完成家庭nas的任务;
  2. 对于共享文件夹,访问用户应该有对应的权限,否则可能出现权限问题
    树莓派设置samba文件共享

参考

  1. https://tutorials.ubuntu.com/tutorial/install-and-configure-samba#0

本文最后修改日期:2019年10月25日

One thought on “树莓派设置samba文件共享

留言评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select * from vps_autoblog_queue where is_running >0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=6 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=6 and source_url_key='85f8e27ce55bd78fd33f47d2b1409198'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(6,'https://www.hijk.pw/post-sitemap.xml','85f8e27ce55bd78fd33f47d2b1409198',1750608111,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=4 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=4 and source_url_key='54b1dccf98c13c81f546faf82132bc77'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(4,'https://ssr.tools/sitemap-posttype-post.2020.xml','54b1dccf98c13c81f546faf82132bc77',1750608111,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=2 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=2 and source_url_key='91372ddcd9e4809b115feaa5b6f00815'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(2,'https://tlanyan.me/post-sitemap.xml','91372ddcd9e4809b115feaa5b6f00815',1750608111,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=7 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=7 and source_url_key='569e17863f7693f1afa9e9256af9dcff'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(7,'https://aisoa.cn/sitemap.xml','569e17863f7693f1afa9e9256af9dcff',1750608111,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=9 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=9 and source_url_key='cc9416f8df40d8c3a48e66856b1cd6fd'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(9,'https://www.v2rayssr.com/sitemap.xml','cc9416f8df40d8c3a48e66856b1cd6fd',1750608111,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=10 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=10 and source_url_key='74714f67855820f0c701ce905b231f27'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(10,'https://doubibackup.com/sitemap.xml','74714f67855820f0c701ce905b231f27',1750608111,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,is_running,last_post_time,post_interval,not_check_stoped from vps_autoblog_queue WHERE is_running>0 and fetched=0 order BY id ASC

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,sn_id from vps_autoblog_queue WHERE is_running=0 and fetched=0 order BY id ASC LIMIT 1