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
Play WSL - Replace Win10's native file sharing with Samba services

Windows7
Play WSL - Replace Win10's native file sharing with Samba services
Play WSL - Replace Win10's native file sharing with Samba services

WindowsXP
Play WSL - Replace Win10's native file sharing with Samba services
Play WSL - Replace Win10's native file sharing with Samba services

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”:
    Play WSL - Replace Win10's native file sharing with Samba services
  • 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”:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Find Server Service:
    Play WSL - Replace Win10's native file sharing with Samba services
  • 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)
    Play WSL - Replace Win10's native file sharing with Samba services
  • Restart the system, then open the “Microsoft Store” application mall, and enter it in the search barwsl
    Play WSL - Replace Win10's native file sharing with Samba services
  • 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:
    Play WSL - Replace Win10's native file sharing with Samba services
  • After installation, you can find Ubuntu in the Start Menu:
    Play WSL - Replace Win10's native file sharing with Samba services
  • 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
    Play WSL - Replace Win10's native file sharing with Samba services
  • Install Samba package, command:sudo apt install samba
    Play WSL - Replace Win10's native file sharing with Samba services

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:
    Play WSL - Replace Win10's native file sharing with Samba services
  • Shared directories can be accessed by inputting local IP addresses through Windows local resource managers:
    Play WSL - Replace Win10's native file sharing with Samba services
  • 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
    Play WSL - Replace Win10's native file sharing with Samba services

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”:
    Play WSL - Replace Win10's native file sharing with Samba services

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

Looking for frustration 1.0

I believe you have a basic understanding of trust in yesterday’s article. Today we will give a complete introduction to trust. Why choose rust It’s a language that gives everyone the ability to build reliable and efficient software. You can’t write unsafe code here (unsafe block is not in the scope of discussion). Most of […]