Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一口气搞定 WSL 的文件共享(Samba) #15

Open
hexh250786313 opened this issue May 15, 2021 · 2 comments
Open

一口气搞定 WSL 的文件共享(Samba) #15

hexh250786313 opened this issue May 15, 2021 · 2 comments
Labels
post blog post type: POST

Comments

@hexh250786313
Copy link
Owner

hexh250786313 commented May 15, 2021

不要点开, 博客网站用的
博文置顶说明
本文主要介绍如何取消 Win10 的文件共享,让 WSL 或 WSL2 的 Samba 共享服务代替 Win10 的共享,让局域网可以访问 WSL 中的共享文件

参考

关闭 Win10 中的相关端口

Linux 中的 Samba 服务主要用到 139 和 445 这两个端口,因此首先要取消在 Win10 中的这两个端口

  • 139 端口:网络和 Internet - 更改适配器选项 - 右键当前网络对象属性 - 选中 TCP/IPv4 属性 - 高级 - WINS - 禁用 TCP/IP 上的 NetBIOS
  • 445 端口:服务 - 找到 Server 服务 - 启动类型禁用 - 重启

WSL samba 配置

安装

sudo apt-get install samba

配置

sudo vi /etc/samba/smb.conf

在最末尾添加类似如下的代码(share 是共享文件夹的名字,path 是路径,自行替换):

[share]
  path = /home/me/share
  available = yes
  browseable = yes
  writable = yes
  public = yes

重启 samba

sudo service smbd restart

暴露端口(WSL2 需要,WSL1 不需要)

把上述的 139 和 445 端口暴露出去并创建防火墙规则,具体做法参考这篇:一口气搞定 WSL2 的网络问题

一些 samba 的使用

  • 分享的文件夹权限问题,一般来说需要 777 权限: chmod 777 /YourShare,但是需要在其更高级别的权限上设置,例如: 要分享 /home/my/Desktop 这个文件夹,需要执行 chmod 777 /home/my 保证其上级文件夹 /my 的权限(当然 Desktop 也有可能权限不够,可能还需要再执行一遍 chmod 777 /home/my/Desktop),结论是需要保证每一级的文件夹访问权限都是可访问的
  • 可以通过 smbclient //localhost/<SharedDirName> 指令来进入分享目录测试 smb 是否已经成功,需要输入访问密码,如果设置了 public = yes,此处可以不输入密码直接回车进入目录
  • 执行完 smbclient //localhost/<SharedDirName> 后进入分享目录,可以通过 ls 测试是否可以访问目录,如果有如下提示说明权限设置不足:

    NT_STATUS_ACCESS_DENIED

@hexh250786313 hexh250786313 added post blog post type: POST and removed post blog post type: POST labels May 15, 2021
@carloscn
Copy link

carloscn commented Jun 22, 2024

一口气搞定 WSL2 的网络问题 失效啦!

#12

@hexh250786313
Copy link
Owner Author

@carloscn 被 vercel 背刺了,用 https://blog.hexh.xyz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
post blog post type: POST
Projects
None yet
Development

No branches or pull requests

2 participants