树莓派使用Samba共享文件夹

本文介绍如何通过安装和配置Samba软件将Raspberry Pi作为简易网络附加存储(NAS)设备,实现与Windows计算机之间的文件共享。

转载自:http://raspberrypihq.com/how-to-share-a-folder-with-a-windows-computer-from-a-raspberry-pi/

 

Sharing files over the network is often very useful. Whether you need to transfer media files to the Raspberry Pi or you want to use the raspberry as a simple Network-Attached Storage (NAS) device, this guide will show you how to enable file sharing of a folder on the Raspberry Pi running the Raspbian OS.

 

Prerequisites & Equipment

You are going to need the following:

  • A Raspberry Pi (Buy here)
  • A SD Card flashed with the Raspbian OS (Here is a guide if you need)
  • Access to the Raspberry either via keyboard and a monitor or remotely
  • A home network
  • A Windows computer (for this guide we will be running Windows 7)

Install and configure required software

To share network folders to a Windows computer we need to install some special software on the Raspberry Pi. The software providing the secret sauce this time is called Samba. The Samba software package implements the SMB protocol and provides support for the Windows naming service (WINS) and for joining a Windows Workgroup.

Installing the software is easy – login to your Raspberry Pi and run:

sudo apt-get install samba samba-common-bin

After installation configure the software by opening the file /etc/samba/smb.conf using the command:

sudo nano /etc/samba/smb.conf

Read through the file and make sure you have the following parameters set:

workgroup = WORKGROUP
wins support = yes

You can use anything as your workgroup name as long as it is alphanumerical and matches the workgroup you would like to join. The default workgroup in Windows 7 is WORKGROUP.

Setup folder to share

Next step is to create the folder you would like to share. To create a folder called “share” in your home directory do the following:

mkdir ~/share

With the folder created we can now tell the Samba software to share it on the network. Open the file /etc/samba/smb.conf using the command:

sudo nano /etc/samba/smb.conf

Scroll to the bottom and add the following:

[PiShare]
 comment=Raspberry Pi Share
 path=/home/pi/share
 browseable=Yes
 writeable=Yes
 only guest=no
 create mask=0777
 directory mask=0777
 public=no

Notice how we tell Samba that public access is not allowed via “public=no” – this means that anyone wanting to access the shared folder must login with a valid user.

In this case the valid user is the user called “pi”. To let Samba know that “pi” is a network user run the command:

sudo smbpasswd -a pi

And enter pi’s password twice (default: raspberry).

At this point we can now login to the share from our Windows computer – use Domain: raspberrypi, User: pi and Password: raspberry (unless you changed the password) as you can see below:

Login to shared folder on Raspberry Pi

If you do not want to deal with logging in you can always make the share publicly available by changing the config file to say:

public=yes

However please note that this is extremely dangerous since anyone will be able to access, modify and delete your files.

转载于:https://www.cnblogs.com/itlqs/p/6812453.html

树莓派上配置和使用共享文件夹,通常可以通过 **Samba** 服务实现,这是一种在 Linux 和 Windows 之间共享文件和打印机的标准协议。以下是一个详细的配置流程,涵盖安装、配置、访问等方面。 --- ### ### 安装 Samba 服务 首先,确保树莓派的软件包列表是最新的,并安装 Samba 及其相关工具: ```bash sudo apt-get update sudo apt-get install samba samba-common-bin ``` 该步骤参考了树莓派学习笔记中的安装方法 [^3]。 --- ### ### 配置 Samba 共享 安装完成后,需要编辑 Samba 的配置文件 `smb.conf`,位于 `/etc/samba/` 目录下。可以使用 `nano` 编辑器打开: ```bash sudo nano /etc/samba/smb.conf ``` 在文件末尾添加如下内容,以配置一个共享文件夹(例如 `/home/pi/shared`): ```ini [SharedFolder] path = /home/pi/shared browseable = yes writable = yes guest ok = yes read only = no ``` 保存并退出编辑器(在 `nano` 中按 `Ctrl+O` 保存,`Ctrl+X` 退出)。 --- ### ### 设置共享文件夹权限 确保共享目录存在,并设置适当的权限: ```bash mkdir -p /home/pi/shared chmod -R 0777 /home/pi/shared ``` 这将允许所有用户读写该目录。 --- ### ### 重启 Samba 服务 修改配置后,需要重启 Samba 服务以应用更改: ```bash sudo systemctl restart smbd ``` --- ### ### 在 Windows 上访问共享文件夹 在 Windows 上,可以通过以下方式访问树莓派共享文件夹: 1. 按下 `Win + R` 键,输入 `\\树莓派的IP地址`,例如 `\\192.168.1.100`。 2. 系统会列出共享文件夹,点击进入即可访问。 3. 如果需要映射为网络驱动器,可在“此电脑”中选择“映射网络驱动器”,并输入上述路径。 如果遇到无法访问的问题,可能需要在 Windows 注册表中启用不安全的来宾访问: - 打开注册表编辑器(`regedit`)。 - 定位到 `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters`。 - 创建一个名为 `AllowInsecureGuestAuth` 的 DWORD(32位)值,并将其设置为 `1` [^4]。 --- ### ### 在 Android 设备上访问共享文件夹 在 Android 上,可以使用支持 SMB 协议的文件管理器,例如 **ES 文件浏览器** 或 **Solid Explorer**: 1. 打开文件管理器,选择“网络”或“局域网”选项。 2. 输入树莓派的 IP 地址,即可浏览共享文件夹内容。 3. 可以选择挂载该共享路径,方便后续访问。 --- ### ### 使用 FTP 传输文件(可选) 除了 Samba,还可以使用 FTP 协议进行文件传输,推荐使用 **FileZilla** 客户端: 1. 在树莓派上安装 vsftpd: ```bash sudo apt-get install vsftpd ``` 2. 编辑配置文件 `/etc/vsftpd.conf`,启用本地用户访问: ```ini local_enable=YES write_enable=YES ``` 3. 重启服务: ```bash sudo systemctl restart vsftpd ``` 4. 使用 FileZilla 输入树莓派的 IP 地址、用户名(如 `pi`)和密码进行连接 [^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值