树莓派官方文档之samba

Samba/CIFS

Samba is a implementation of the SMB/CIFS networking protocol that is used by Windows devices to provide shared access to files, printers, and serial ports etc. There is a comprehensive Wikipedia page about Samba and its capabilities.

Samba 是 SMB/CIFS 网络协议的实现,该协议被 Windows 设备用于共享访问文件、打印机和串行端口等。
维基百科上有一个综合介绍 Samba 及其作用的页面。

This page will explain how to use a subset of the Samba system to ‘mount’ a shared folder on a Windows device so it appears on your Raspberry Pi, or to share a folder on your Raspberry Pi so it can be accessed by a Windows client.

这个页面将解释如何使用 Samba 系统的子集在 Windows 设备上安装一个共享文件夹,这样它就会出现在你的 Raspberry Pi 上,
或者在你的 Raspberry Pi 上共享一个文件夹并且可以被 Windows 客户端访问。

Installing CIFS/Samba support 安装 CIFS/Samba 支持

By default, Raspbian does not include CIFS/Samba support, but this can easily be added. The following commmands will install all the required components for using Samba as a server or a client.

默认Raspbian 不包含 CIFS/Samba 支持,但是这很容易添加。 下面的命令将安装使用 Samba 作为服务器或客户端所需的所有组件。

sudo apt-get update
sudo apt-get install samba samba-common-bin smbclient cifs-utils

Using a shared Windows folder 使用共享 Windows 文件夹

First, you need to share a folder on your Windows device. This is quite a convoluted process!

首先,你需要在 Windows 设备上共享一个文件夹。 这是一个相当复杂的过程!

Turn on sharing 开始分享
  1. Open the Networking and Sharing Centre by right-clicking on the system tray and selecting it
  2. Click on Change advanced sharing settings
  3. Select Turn on network discovery
  4. Select Turn on file and printer sharing
  5. Save changes

  1. 右键单击并选择系统托盘来打开网络和共享中心
  2. 点击更改高级共享设置
  3. 选择打开网络发现
  4. 选择打开文件和打印机共享
  5. 保存更改
Share the folder 共享文件夹

You can share any folder you want, but for this example, simply create a folder called share.

你可以共享任何你想共享的文件夹,但是在这个例子中,简单起见就创建一个名为 share 的文件夹。

  1. Create the folder share on your desktop.
  2. Right-click on the new folder, and select Properties.
  3. Click on the Sharing tab, and then the Advanced Sharing button
  4. Select Share this folder; by default, the share name is the name of the folder
  5. Click on the Permissions button
  6. For this example, select Everyone and Full Control (you can limit access to specific users if required); click OK when done, then OK again to leave the Advanced Sharing page
  7. Click on the Security tab, as we now need to configure the same permissions
  8. Select the same settings as the Permissions tab, adding the chosen user if necessary
  9. Click OK

  1. 在你的桌面上创建一个名为 share 的文件夹
  2. 右击新文件夹,然后选择属性
  3. 点击共享选项卡,然后点击高级共享按钮
  4. 选择共享此文件夹; 默认情况下,共享名称是文件夹的名称
  5. 点击权限按钮
  6. 在这个例子中,选择Everyone完全控制(如果需要,您可以限制访问特定用户) ; 完成后单击确定,然后再次确定离开高级共享页面
  7. 点击安全标签,因为我们现在需要配置相同的权限
  8. 选择与权限选项卡相同的设置,必要时添加所选用户
  9. 点击确定

The folder should now be shared.
该文件夹现在应该被共享。

Windows 10 Sharing Wizard

On Windows 10 there is a Sharing Wizard that helps with some of these steps.

在 windows10上有一个分享向导,它可以帮助你完成这些步骤。

  1. Run the Computer Management application from the Start Bar
  2. Select Shared Folders, then Shares
  3. Right-click and select New Share, which will start up the Sharing Wizard; click Next
  4. Select the folder you wish to share, and click Next
  5. Click Next to use all the sharing defaults
  6. Select Custom and set the required permissions, and click OK, then Finish

  1. 从开始栏运行计算机管理应用程序
  2. 选择共享文件夹,然后分享
  3. 右击并选择新共享,这将启动共享向导; 单击下一步"
  4. 选择要共享的文件夹,然后单击下一步
  5. 单击下一步来使用所有的共享默认值
  6. 选择自定义并设置所需权限,然后单击确定,然后完成
Mount the folder on the Raspberry Pi 在 Raspberry Pi 上挂载文件夹

Mounting* in Linux is the process of attaching a folder to a location, so firstly we need that location.

在 Linux 中挂载是将一个文件夹连接到一个位置的过程,首先我们需要这个位置。

mkdir windowshare

Now, we need to mount the remote folder to that location. The remote folder is the host name or IP address of the Windows PC, and the share name used when sharing it.
We also need to provide the Windows username that will be used to access the remote machine.

现在,我们需要将远程文件夹挂载到该位置。远程文件夹是 Windows PC 的主机名或 IP 地址,以及共享时使用的共享名称。
我们还需要提供用于访问远程计算机的 Windows 用户名。

sudo mount.cifs //<hostname or IP address>/share /home/pi/windowshare -o user=<name>

You should now be able to view the content of the Windows share on your Raspberry Pi.

现在你应该可以在你的 Raspberry Pi 上查看 Windows 分享的内容。

cd windowshare
ls

Sharing a folder for use by Windows 共享文件夹供 Windows 使用

Firstly, create a folder to share. This example creates a folder called shared in the home folder of the current user, and assumes the current user is pi.

首先,创建一个文件夹来共享。这个例子是在当前用户的家目录下创建一个名为 share 的文件夹,并假设当前用户是 pi。

cd ~
mkdir shared

Now we need to tell Samba to share this folder, using the Samba configuration file.

现在我们需要告诉 Samba 共享这个文件夹,通过使用 Samba 配置文件。

sudo nano /etc/samba/smb.conf

At the end of the file, add the following to share the folder, giving the remote user read/write permissions:

在文件的末尾,添加以下来分享文件夹,给予远程用户读写权限:

[share]
    path = /home/pi/shared
    available = yes
    valid users = pi
    read only = no
    browsable = yes
    public = yes
    writable = yes

In the same file, find the workgroup line, and if necessary, change it to the name of the workgroup of your local Windows network.

在同一个文件中,查找workgroup所在的行,如果有必要可以将其更改为本地 Windows 网络的工作组名称。

workgroup = <your workgroup name here>

That should be enough to share the folder. On your Windows device, when you browse the network, the folder should appear and you should be able to connect to it.

这些对于分享这个文件夹来说应该足够了。在你的 Windows 设备上浏览网络时,文件夹应该会出现,你也应该可以连接到它。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
05-27
Samba是一个开源的软件套件,可以让Unix/Linux系统共享文件和打印机,与Windows系统进行文件和打印机共享。使用Samba,你可以在Unix/Linux系统上创建一个Windows兼容的文件服务器,让Windows系统用户可以方便地访问共享文件和打印机。 以下是Samba的一些基本概念和使用方法: 1. Samba服务器:Samba服务器是运行Samba软件的Unix/Linux系统,它可以作为文件服务器和打印机服务器,与Windows系统进行文件和打印机共享。 2. Samba共享:Samba共享是Samba服务器上的一个目录或文件,可以被Windows系统用户访问和共享。 3. Samba用户:Samba用户是Samba服务器上的一个用户账户,用于访问Samba共享。你需要为每个需要访问Samba共享的用户创建一个Samba用户账户,并设置相应的访问权限。 4. Samba配置文件:Samba配置文件是Samba服务器的配置文件,用于指定Samba共享和Samba用户等信息。Samba配置文件通常位于/etc/samba/smb.conf。 5. Samba客户端:Samba客户端是运行Windows系统的电脑,可以访问Samba共享和打印机。 以下是一些基本的Samba命令: 1. 安装Samba软件: ``` sudo apt-get update sudo apt-get install samba ``` 2. 创建Samba用户账户: ``` sudo smbpasswd -a username ``` 其中,username是要创建的Samba用户账户。 3. 修改Samba配置文件: ``` sudo nano /etc/samba/smb.conf ``` 在文件中添加Samba共享的配置信息,如下所示: ``` [share-name] comment = My Samba Share path = /path/to/share browsable = yes read only = no guest ok = no valid users = username ``` 其中,share-name是Samba共享的名称,comment是Samba共享的注释,path是Samba共享的路径,browsable指定Samba共享是否可浏览,read only指定Samba共享是否只读,guest ok指定是否允许访客访问该共享,valid users指定可以访问该共享的Samba用户。 4. 重启Samba服务: ``` sudo service smbd restart ``` 5. 在Windows系统中访问Samba共享: 打开Windows资源管理器,输入Samba服务器的IP地址或主机名,例如: ``` \\192.168.0.100 ``` 或者: ``` \\samba-server ``` 其中,192.168.0.100是Samba服务器的IP地址,samba-server是Samba服务器的主机名。然后,输入Samba用户账户和密码,即可访问Samba共享。 在使用Samba时,需要注意安全问题,避免未授权用户访问Samba共享。你可以在Samba配置文件中设置相应的安全选项,以保护Samba共享的安全性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值