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:
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:
- Release 139,445 ports occupied by Windows
- Install WSL and Ubuntu distributions
- Install the Samba service and configure it
- Change firewall configuration
- 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 LISTENING
You can see:
- 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:
- Click “Properties” to open the “Ethernet Properties” interface:
- Select the “TCP/IPv4” project and click on “Properties” to open the “TCP/IPv4 Properties” interface:
- Click “Advanced” and select the “WINS” tab. Check “Disable NetBIOS on TCP/IP”:
- 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.
Release port 445
- Open the running window by “WIN+R” and enter:
services.msc
Open the service management interface:
- 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:
- Double-click the Server service, open the property interface, change “Start Type” to disable, and click “Stop”:
- Restart the system after setting up.
- After the reboot is complete, it will pass again.
netstat -a|findstr LISTENING
The command checks the port usage and finds that port 445 has been released successfully.
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)
- Restart the system, then open the “Microsoft Store” application mall, and enter it in the search bar
wsl
:
- Select Ubuntu 16.04 from the search results (other distributions should be OK, this test is Ubuntu), and install it:
- The installation process is faster, thanks to the broadband at home:
- After installation, you can find Ubuntu in the Start Menu:
- Click on the icon to open the console, or through the “Run” interface, first open the “CMD” window, and then through
bash
Command into Ubuntu’s command line mode:
Install the Samba service and configure it
Install Samba services:
- Upgrade apt-get tool first, command:
sudo apt-get update
:
- Install Samba package, command:
sudo apt install samba
:
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.conf
Here, a user private directory is configuredhomes
And a shared directory that everyone can read and writeshare
The corresponding directories on windows areC:\private\username>
As well asc:\share
:
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