使用 Samba 在 VirtualBox 中与 Windows 主机共享 Linux 客户机的文件夹

使用 Samba 在 VirtualBox 中与 Windows 主机共享 Linux 客户机的文件夹

我想在 VirtualBox 中将 Linux 客户机上的一个文件夹与 Windows 主机共享(如果可能的话,具有读写权限)。

我在这两个链接中读到:这里这里可以使用 Samba 来做到这一点,但我有点迷茫,需要更多有关如何继续的信息。

到目前为止,我已成功设置了两个网络适配器(一个 NAT 和一个仅主机),并在 Linux 客户机上安装了 Samba,但现在我有以下问题:

  1. 我需要输入什么samba.conf才能从 Linux 客户机共享文件夹?(教程上述其中一个链接中提供的说明仅解释了如何共享主目录)
  2. 我需要在客户机上运行任何 Samba 命令来启用共享吗?
  3. 如何确保这些文件夹仅对主机操作系统可用,而不在互联网上可用?
  4. 设置 Linux 客户机后,如何从 Windows 主机访问每个单独的共享文件夹?我读到我需要在 Windows 上安装驱动器才能执行此操作,但我是否使用 Samba 登录或 Linux 登录,是否也使用 localhost?或者我需要为此设置一个 IP 吗?

谢谢!

答案1

  1. 这些是如何在 smb.conf 中定义共享的示例

    [readonly-share]
       comment = some share
       path = /this/folder/is/shared
       guest ok = no
       browseable = yes
       read only = yes
    
    [read-write-share]
       comment = another share
       path = /this/folder/is/writable
       guest ok = no
       browseable = yes
       read only = no
       create mask = 0777
       directory mask = 0777
       force create mode = 777
       force directory mode = 777
       force security mode = 777
       force directory security mode = 777
    
  2. 编辑 smb.conf 后,运行“testparm”检查更改,然后让守护进程使用“service smbd restart”重新读取配置

  3. (不确定这个)
    使用“NAT”和“仅主机”虚拟网卡,您应该是安全的。要从主机以外的任何其他计算机访问来宾的服务,您需要在主机上设置端口转发或配置“桥接”虚拟网卡。

  4. 身份验证类型可以在 smb.conf 中设置。Ubuntu 的 samba conf 中的默认设置为“security = user”,这意味着您必须使用有效的用户帐户进行身份验证。(除非您已设置“guest ok = yes”)

    要从 Windows 主机访问共享,您必须使用来宾的 IP 地址。VBox NAT 使用“10.0.2.15”之类的地址。要从主机访问共享“readonly-share”,您可以在文件资源管理器的地址栏中输入如下 URI:

    \\10.0.2.15\readonly-share
    

答案2

在 bytesum 给出的答案中,readonly-share 不能是完整路径,而是去掉 $HOME 部分的路径。例如:在我的情况下,我正在测试共享 /home/me/Documents;我的机器名为 MYMACHINE。因此在 Windows7 中,我必须在映射网络驱动器时指定:

\\MYMACHINE\Documents

注意没有 /home/me。问题解决了。

答案3

**[Global Section]**
workgroup=WORKGROUP[your workgroup name here mine is"WORKGROUP"]
interfaces=your guest ip here
allow hosts=windows ip here
**[Share Details]**
path=samba share path
browsable=yes
readable=yes

相关内容