win10 WSL(1903)安装samba服务器实现文件共享

基于Linux开发的时候经常需要搭建虚拟机,如果只有一台电脑的话安装虚拟机很容易拖慢电脑速度。微软win10系统提供了一个新的解决方案,它内置了Linux子系统,可以直接在这个子系统里面安装samba,然后运行即可。我第一次安装的时候遇到一些问题,无法访问成功,samba服务无法启动,看log是权限问题,网上搜了一圈也没说个所以然出来,google了一篇完整的教程,讲的特别详细,完全按照它写的重新安装wsl,最终成功了。

电脑版本:1903

wsl子系统 16.04

源地址:https://developpaper.com/play-wsl-replace-win10s-native-file-sharing-with-samba-services/

Play WSL – Replace Win10’s native file sharing with Samba services

Time:2019-4-8

Play WSL – Replace Win10’s native file sharing with Samba services

People who are used to Linux systems must feel that Samba services are more flexible and convenient. How to build efficient Samba services on Windows systems? This paper introduces how to build Samba file sharing service on Win10 system through WSL.

The background is that there is only one desktop computer in the family. On the one hand, it is occasionally used by the family. On the other hand, it is the data center of the family, which mounts several hard disks. So the system uses Windows 10, but in order to facilitate flexible file sharing, Samba service has been considered. There are many ways to achieve this goal. We can consider using virtual machines, such as VMWare, VirtualBox, Hyper-V, or CygWin. Because Windows 10 provides WSL, this paper introduces another way, which is also a more efficient way to build Samba services using WSL.

background knowledge

Windows File Sharing Service

Using the network to provide file access services to the outside world, it is now widely used for file sharing within the LAN, such as millet box, mobile phone, PC, including Mac, through ports 139 or 445.

  • 139 – Early Windows SMB runs on NBT (NetBIOS over TCP/IP), using port 139
  • 445 – Windows 2000 and above version, SMB can run directly with TCP/IP, using 445 port, more efficient

The test results show that WinXP only accesses 139 ports, Win7 accesses 139 and 445 ports, and Win10 accesses 445 ports. The test results are as follows:

Windows10
Play WSL - Replace Win10's native file sharing with Samba services
win10 WSL(1903)安装samba服务器实现文件共享_第1张图片

Windows7
win10 WSL(1903)安装samba服务器实现文件共享_第2张图片
win10 WSL(1903)安装samba服务器实现文件共享_第3张图片

WindowsXP
Play WSL - Replace Win10's native file sharing with Samba services
win10 WSL(1903)安装samba服务器实现文件共享_第4张图片

WSL(Windows Subsystem for Linux)

It is on Windows 10 system that the Windows kernel is encapsulated so that it can directly support the Linux executable program in ELF format. It feels a little like GNU/Windows.
Now, based on WSL, there are many Linux distributions, including Ubuntu, Debian, Suse, Kali, etc. It is very convenient to run Linux distributions in Windows, to learn and use various Linux tools, and to seamlessly integrate various services in Linux into Windows environment, such as Samba services, SSH services, etc.

Samba services

In order to realize that UNIX, Linux and other non-Windows can access the file sharing resources of Windows, a Daniel has analyzed the SMB (Server Message Block) protocol in reverse, and then developed an open source software Samba according to the reverse analysis protocol, which can enable UNIX, Linux, Mac and other systems to share files with Windows. At present, the latest Samba can even provide AD, DC and other services.

Overall plan

Based on the above background knowledge, the scheme of building Samba service through WSL on Windows 10 is as follows:

  1. Release 139,445 ports occupied by Windows
  2. Install WSL and Ubuntu distributions
  3. Install the Samba service and configure it
  4. Change firewall configuration
  5. Final test

Implementation steps

Release 139,445 ports occupied by Windows

Release port 139

  • The installed Windows 10 system will listen on ports 139 and 445 by default.netstat -a|findstr LISTENINGYou can see:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Disable NetBIOS over TCP/IP. Disable it through the following operations. In the “Change adapter settings” interface, double-click the corresponding network card and open the “Ethernet status” interface:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Click “Properties” to open the “Ethernet Properties” interface:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Select the “TCP/IPv4” project and click on “Properties” to open the “TCP/IPv4 Properties” interface:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Click “Advanced” and select the “WINS” tab. Check “Disable NetBIOS on TCP/IP”:
    win10 WSL(1903)安装samba服务器实现文件共享_第5张图片
  • After clicking “OK”, it will take effect. If there are multiple network cards, each network card should follow the steps mentioned above. After the operation is finished, it will be checked through the netstat command. It is found that port 139 is no longer listening.
    Play WSL - Replace Win10's native file sharing with Samba services

Release port 445

  • Open the running window by “WIN+R” and enter:services.mscOpen the service management interface:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Find the Computer Browser service, double-click the service to open the property interface, change “Start Type” to disable, and click “Stop”:
  • Find Server Service:
    win10 WSL(1903)安装samba服务器实现文件共享_第6张图片
  • Double-click the Server service, open the property interface, change “Start Type” to disable, and click “Stop”:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Restart the system after setting up.
  • After the reboot is complete, it will pass again.netstat -a|findstr LISTENINGThe command checks the port usage and finds that port 445 has been released successfully.
    Play WSL - Replace Win10's native file sharing with Samba services

Install WSL and Ubuntu distributions

  • In the “Programs and Functions” management interface, click “Enable or Close Windows Functions” and in the “Windows Functions” list, check “Windows Subsystem for Linux” (Note: Different Windows versions may have different names, I tried version 17134.191)
    win10 WSL(1903)安装samba服务器实现文件共享_第7张图片
  • Restart the system, then open the “Microsoft Store” application mall, and enter it in the search barwsl
    win10 WSL(1903)安装samba服务器实现文件共享_第8张图片
  • Select Ubuntu 16.04 from the search results (other distributions should be OK, this test is Ubuntu), and install it:
    Play WSL - Replace Win10's native file sharing with Samba services
  • The installation process is faster, thanks to the broadband at home:
    win10 WSL(1903)安装samba服务器实现文件共享_第9张图片
  • After installation, you can find Ubuntu in the Start Menu:
    win10 WSL(1903)安装samba服务器实现文件共享_第10张图片
  • Click on the icon to open the console, or through the “Run” interface, first open the “CMD” window, and then throughbashCommand into Ubuntu’s command line mode:
    Play WSL - Replace Win10's native file sharing with Samba services

Install the Samba service and configure it

Install Samba services:

  • Upgrade apt-get tool first, command:sudo apt-get update
    win10 WSL(1903)安装samba服务器实现文件共享_第11张图片
  • Install Samba package, command:sudo apt install samba
    win10 WSL(1903)安装samba服务器实现文件共享_第12张图片

Configure Samba services:

Here is just a configuration example. Let the service run with the simplest configuration. If you need to know more about the configuration of samba service, it is recommended to find more strategies online.

  • Open the configuration file and edit it:sudo vi /etc/samba/smb.confHere, a user private directory is configuredhomesAnd a shared directory that everyone can read and writeshareThe corresponding directories on windows areC:\private\username>As well asc:\share
    Play WSL - Replace Win10's native file sharing with Samba services

The details of the configuration file are as follows:

[global]
    workgroup = WORKGROUP
    server string = jamieli-vm
    log file = /var/log/samba/log.%m
    log level = 0
    max log size = 1000
    security = user
    map to guest = Bad User
    passdb backend = smbpasswd
    smb passwd file = /etc/samba/smbpasswd
    username map = /etc/samba/smbusers
    guest account = nobody
    os level = 64

[homes]
comment
= user private
path
= /mnt/c/private/%u
read only
= No

[share]
comment
= home share
guest ok
= Yes
path
= /mnt/c/share
read only
= No
public = Yes

  • Write the configuration file, because it is user security mode, so you need to add an SMB user, command:sudo smbpasswd -a jamieliAnd enter the password:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Start the smbd service,sudo service smbd start
    Play WSL - Replace Win10's native file sharing with Samba services
  • Looking at the temporary port usage in the Windows CMD window, we found that 139 and 445 were occupied by smbd services:
    win10 WSL(1903)安装samba服务器实现文件共享_第13张图片
  • Shared directories can be accessed by inputting local IP addresses through Windows local resource managers:
    win10 WSL(1903)安装samba服务器实现文件共享_第14张图片
  • stayhomesIn the directory, create atestCatalog, you can see the correspondingc:\private\jamieliIn the catalog, there is another same catalog:
    Play WSL - Replace Win10's native file sharing with Samba services
  • But through another machine access, we found that the access failed because of the firewall settings. In the next section, we will talk about how to configure the firewall:
    Play WSL - Replace Win10's native file sharing with Samba services
    win10 WSL(1903)安装samba服务器实现文件共享_第15张图片

Change firewall configuration

  • In the “Run” interface, enter:wf.mscStart the firewall configuration interface, select the “Inbound Rules” menu, and click “New Rules” on the right side:
    Play WSL - Replace Win10's native file sharing with Samba services
  • In the New Inbound Rules Wizard interface, select Port:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Select “TCP” and input port “139,445”:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Select Allow Connection:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Call it “samba service” and click “finish”:
    win10 WSL(1903)安装samba服务器实现文件共享_第16张图片

The final test:

  • Access tests are conducted under Mac. CMD+K is used under Finder interface. Connect Server interface is opened and the server address configured before is entered.
    Play WSL - Replace Win10's native file sharing with Samba services
  • Enter the SMB account and password added through the smbpasswd command:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Successful access to Samba services built through WSL will not affect the closure of the Ubuntu window at this time, and the service will continue to run in the background:
    Play WSL - Replace Win10's native file sharing with Samba services

summary

Through the process of service configuration, we have a general understanding of the use of WSL. Through this way, we can also deploy SSH and other services on Windows. It is a good news for those who are familiar with Linux system.
At the same time, through some tools, these services can also be packaged as Windows Services, which are automatically loaded when Windows starts.
Welcome to exchange with each other, Email: [email protected], WeChat: jamieli

Reference resources

NetBIOS over TCP/IP
Windows Subsystem for Linux Documentation

Recommended Today

Using PowerDesigner Reverse Engineering to Export PDM Model and Generate Documents

Recently, it is necessary to reconstruct and optimize the old project. Because the project is several years ago, the relevant design information is not complete, and the most basic database design documents are not available, so we can only use PowerDesigner reverse engineering to export PDM model and generate word document. Here is a brief […]

  • Inducting of common protocol ports in computer networks
  • Practice VLAN under Linux System
  • Plus: One problem with not having remote access to server is that openssh is not configured properly and the file VIM cannot be edited properly.
  • Pre-sniffing ForeSpider Tutorial: Collection Preview
  • [Source learning] Front-end caching tools fast-memoize and nano-memoize
  • React-router Brower Router Refresh 404 Apache Server Solution
  • Instance Method for Deploying Reaction Project on nginx
  • Principle and implementation of SSH secret-free login on Linux
  • Tutorial for ss-proxy
  • Ubuntu server installs Apache to mount web pages into it

你可能感兴趣的:(Linux,应用程序开发)