In the Windows operating system, there is a feature called file sharing. On one computer, you can set up windows-shared folder that will be accessible to all computers on the local network. This is done using the SMB protocol, which has several versions. In Linux, you can open and create shared folders using Samba.
The Samba server supports all versions of the SMB protocol. However, there are some compatibility issues. In this article, I will explain how to access a Windows Shared folder in Linux using popular desktop environments and the command line.
Table of Contents
- Why It May Not Work?
- Ensure that Everything is Set Up Correctly in Windows
- Finding Shares in Linux Terminal
- Open Shared Folder in KDE Dolphin
- Open Share in GNOME Nautilus
- Mounting a Shared Folder in the Terminal
- Wrapping Up
Why It May Not Work?
In older versions of Linux distros and Windows 7 everything worked fine because they used the SMB1 protocol. However, there have been several changes recently. In 2017, the Wannacry virus emerged, which exploited vulnerabilities in the SMB1 protocol. As a result, modern versions of Windows have disabled support for SMB1 and now use SMB3 by default. Samba has also disabled SMB1 since version 4.11. However, SMB2 and SMB3 lack support for device discovery in the local network.
In general, this is no longer necessary because there is a network discovery protocol called Zeroconf. In Linux, its open-source implementation, Avahi, is used. Linux servers and NAS storage can publish themselves on the local network using this protocol. So that, there is no need to support it in SMB. However, Microsoft decided to use its own protocol called WS-Discovery, and that's where the problems began.
At the time of writing this article, Linux system has issues with discovering shared folders in the local network. The Nautilus file manager in GNOME does not support WS-Discovery at all, and there are no production-ready terminal utilities for it either. You can track the current status of implementing WS-Discovery support in this GVFS issue. However, in 2020, the KDE team added support for this protocol in the Dolphin file manager using kdsoap-ws-discovery-client.
Later, a program for KDE called Smb4k appeared, which can discover network resources using Avahi and the WS-Discovery protocol, but it needs to be compiled with a special option. So that, in GNOME, you can only open a Windows shared folder by knowing the IP address of the computer where it is located. Whereas in KDE, it is a bit more convenient to do so.
Ensure that Everything is Set Up Correctly in Windows
Previously, it was enough to go to File Explorer and enable file sharing there. But it no longer works that way. First, you need to make your current network private in Windows. By default, only private networks are considered secure, and Windows machines can be discovered in them. To do this, open Settings -> Network & Internet -> Ethernet and select Network Profile Type -> Private Network:
If your current network is wireless, you should do the pretty same thing. Next, go back and select Advanced Sharing Settings. In this window, enable Network discovery and File and printer sharing:
Finally, you need to ensure that the firewall is configured correctly and allows SMB connections. To do this, go back to the main Settings menu, then open Privacy & Security -> Firewall & network protection. Click on Allow an app through the firewall:
Make sure that File and printer sharing and Network discovery are enabled for Private networks:
That's it. Now you can go to your Linux machine.
Finding Shares in Linux Terminal
Although there are no command-line tools for working with WS-Discovery, you can try to find devices with shared resources using Nmap. This program cannot search for resources like Avahi does, but it can help you find IP addresses with an open port 445. This port is used by SMB. To do this, you need to install the following packages (Ubuntu):
sudo apt install nmap smbclient
Or Fedora:
sudo dnf install nmap samba-client
Also, you need to find out the IP address range of your local network. You can take your IP address and mask and just replace the fourth digit with zero. For example:
ip -br a
The command for the search will look like this. Replace 192.168.124.0/24 with your local network address range and run it in the the terminal window with sudo privileges:
nmap -p 445 --open -n -Pn 192.168.124.0/24
The -p option specifies the port 445, -Pn option disables ICMP discovery and treats all IP addresses as alive, -n disables DNS hostname resolution. The command may take quite a while, but as a result, it will find hosts with open port 445 if such hosts exist in your local network:
This can't be considered as normal network discovery, but it works. Now you can use smbclient to see which shared folders are on the server that you found. For example:
smbclient -L 192.168.124.63
The command will ask you to enter the share password. Usually, it is password for your Windows user, and then it will show all available shared folders:
Now let's have a look at how to mount them.
Open Shared Folder in KDE Dolphin
To open a shared folder in KDE, you can use the Dolphin file manager. As I mentioned earlier, here you can see all available computers that have network drive on the local network. To do this, run Dolphin, then open Network, and then Shared Folders (SMB):
Click on one of the resources and enter the username and password to view the available folders:
This is what shared folders from Windows 11 look like. Here you can find windows files:
If network discovery does not work in your case, you can still enter the IP address of the resource in the text field at the top of the window and connect to it. For example, smb://192.168.124.63/
Open Share in GNOME Nautilus
If you want to connect to a Windows shared folder in the GNOME graphical interface, you can use the Nautilus file manager. Open Other Locations and find at the bottom of the window the inscription Connect to Server and a field for entering an address.
There's no point in opening the Windows Network item, because GVFS, which is used in GNOME for disk mounting, does not support the WS-Discovery protocol. To connect to a remote windows share located on a server with IP 192.168.124.63, enter this address and press the Connect button:
smb://192.168.124.63
In the next window, you need to enter a password and after that, you can view the files of the shared folder:
After this, you can browse your windows folders.
Additionally, you can use a shortcut on the left panel to access a remote share which is already mounted.
Mounting a Shared Folder in the Terminal
If you want to mount windows share in the terminal, you can use cifs-utils and the mount command. Firstly, install the cifs-utils package. The command for Ubuntu:
sudo apt install cifs-utils
In Fedora:
sudo dnf install cifs-utils
Now, you can execute the mount command specifying the cifs file system type and the username option. Note that you can't mount the root of the cifs share, you need to add any folder in the path. For example, Users on 192.168.124.63:
sudo mount -t cifs -o username=losst //192.168.124.63/Users /mnt/
If you want to have write access to the windows share folder, you need to add the uid option with the identifier of your user. For the first user, it's usually 1000:
sudo mount -t cifs -o username=losst,uid=1000 //192.168.124.63/Users /mnt/
You can find the identifier of the current user in the UID environment variable:
echo $UID
If you want to mount share automatically at system startup, you need to save the share username and password in a credentials file, for example, /etc/share/windows-credentials. For instance:
sudo mkdir -p /etc/share/
/etc/share/windows-credentialsusername=losst
password=password
domain=workgroup
And then add the following line to the /etc/fstab file:
/etc/fstab//192.168.124.63/Users /mnt/share cifs credentials=/etc/share/windows-credentials,uid=1000,nofail 0 0
The nofail option is needed to allow your computer to boot even if the remote folder could not be mounted. After this, reload systemd settings:
sudo systemctl daemon-reload
Create the mount point directory:
sudo mkdir -p /mnt/share
You can check that everything is working using the following command:
sudo mount /mnt/share
If everything is ok, you could see contents of mounted share in the /mnt/share folder:
Wrapping Up
In this article, we looked at how to mount Windows network share in Linux using a graphical interface or in the terminal. Despite some difficulties, this can be used quite effectively. Do you know any other applications or scripts which can help with that? Share their names in the comments section below.