You can share your Raspberry Pi’s files and folders across a network using a piece of software called Samba.
使用Samba通过网络共享树莓派的文件夹.
摘录一段Samba的维基百科:
Samba is a free software re-implementation of the SMB/CIFS networking protocol, and was originally developed by Andrew Tridgell. Samba provides file and print services for various Microsoft Windows clients and can integrate with a Microsoft Windows Server domain, either as a Domain Controller (DC) or as a domain member. As of version 4, it supports Active Directory and Microsoft Windows NT domains.
Samba runs on most Unix, OpenVMS and Unix-like systems, such as Linux, Solaris, AIX and the BSD variants, including Apple’s OS X Server, and OS X client (version 10.2 and greater). Samba is standard on nearly all distributions of Linux and is commonly included as a basic system service on other Unix-based operating systems as well. Samba is released under the terms of the GNU General Public License. The name Samba comes from SMB (Server Message Block), the name of the standard protocol used by the Microsoft Windows network file system.
sudo apt-get install samba samba-common-bin
sudo nano /etc/samba/smb.conf
找到 workgroup 和 wins support 两项并把 workgroup 改成你的 windows 工作组的名字,一般都为 WORKGROUP,wins support 设置成 yes:
workgroup = WORKGROUP wins support = yes
添加以下
[pihome]
comment= RaspberryPi
path=/home/pi
browseable=Yes
writeable=Yes
only guest=no
create mask=0777 directory mask=0777 public=no
到 smb.conf 文件的 Share Definitions 段之后, 一般在最后面, 放到末尾即可. 按 Ctrl+X, 然后Y, 然后回车, 保存退出.
说明: 会在电脑端共享中显示的名称为 raspberrypi
, 分享的文件目录为 /home/pi
, 可浏览, 可写, 不可以用客人身份访问, public设为no, 所以电脑端登录树莓派服务器的时候, 需要输入用户名和密码, 下面设置用户名为pi的密码:
sudo smbpasswd -a pi
会提示输入两次密码, 我仍然设置为 pi 默认的密码 raspberry.
打开Mac的Finder, 找到左侧栏的 共享, 会看到一个名为 raspberrypi 的电脑盘符, 打开它, 我这里出现了 pi 和 pihome 两个文件夹(大概是余毒未清…), 其中, pi文件夹是只读的, pihome文件夹可以读写, 对应的树莓派的目录都是 /home/pi
, 以后我们写程序可以直接用电脑端的编辑器如sublime来写程序, 然后直接存到pihome的某个文件夹即可, 然后可以在终端ssh登录, 切换到文件夹, 运行程序, 这样会方便很多.
参考:
树莓派教程6: 在 Windows PC 和 Raspberry Pi 之间共享文件(图文)
Share your Raspberry Pi’s files and folders across a network
Setting up a SAMBA Server on Raspberry Pi