In the previous article, I explained how to mount a Windows shared folder in Linux. There were certain issues due to the fact that Microsoft uses the WS-Discovery protocol, and Linux still poorly supports this protocol. However, if you need to mount a Samba shared folder, the issues will be roughly the same.
In this article, we will look at how to mount a SMB share in Linux or Windows using a graphical interface.
Table of Contents
- Why It May Not Work?
- How to Access Samba Share in Linux
- How to Open Samba Shared Folder in Windows
- Wrapping Up
Why It May Not Work?
In the past, the SMB1 protocol had a built-in network discovery feature. Starting with Samba 4.11.0, it is disabled by default and is not recommended for use due to security issues. Now the Zeroconf protocol and Avahi service are used in Linux for that purposes. Recent versions of Samba can publish themselves into the local network using Avahi. So that, in most cases, you will see Samba share on another Linux PC without any troubles.
However, Windows will not see your Linux shares. Microsoft uses the WS-Discovery protocol for network discovery, but the developers of Samba decided not to add support for this protocol. There is already a separate service written in Python that can announce a computer through WS-Discovery, which is called WSDD.
In the next sections, we will look at how to ensure that your Samba server is announced using Avahi, and how to configure the announcement manually. This may be relevant for older versions of Samba. Also, we will configure WSDD so that everything works in Windows as well.
How to Access Samba Share in Linux
In this article, I won't go into detail about setting up a Samba file server because there are already many instructions on the internet. Let's focus on how to ensure that it is visible to other Linux machines and troubleshoot if it is not. As I mentioned earlier, this is done using the Avahi service. You need to install it if it is not already installed. The command for Ubuntu is:
sudo apt install avahi-daemon avahi-utils
Or for Fedora:
sudo dnf install avahi avahi-tools
This may be enough for your network folder to be found on another computer because newer versions of Samba can announce themselves via Avahi if they are compiled with this support. This feature can be configured using the multicast dns register option in the global section:
/etc/samba/smb.conf[global]
multicast dns register = yes
Usually, it is enabled by default, so no additional settings are needed here and it makes file sharing between Linux systems easier. You can check whether your server is discovered by Avahi using this command:
avahi-browse --all --terminate --resolve
You will see your server's IP and port 445, in the list. If the automatic announcement does not work, you can configure Avahi to announce Samba service permanently by creating the /etc/avahi/services/samba.service file with the following content:
/etc/avahi/services/samba.service<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_smb._tcp</type>
<port>445</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=LOSST-PC</txt-record>
</service>
</service-group>
Here, the Samba service is published, along with the computer name LOSST-PC, which will make it easier for users to understand that this is the computer they need. Then you need to set the correct permissions for this file and restart Avahi:
sudo chmod 644 /etc/avahi/services/samba.service
sudo systemctl restart avahi-daemon
After this, you will be able to find SMB shares on network. Ensure that you can see smb shares on another PC. If you use GNOME and Nautilus, open Other Locations, and your remote share will appear right here in the Networks list:
You just need to enter the password for it, and after this, you will see shared files:
In the Dolphin file manager you can open the Shared Folders Item in the Network section:
There you will see your share:
How to Open Samba Shared Folder in Windows
If you want your Samba network share to be visible and accessible in Windows, Avahi won't help. You need to install and start the WSDD service. Execute the following command for its installation in Ubuntu:
sudo apt install wsdd
Or in Fedora:
sudo dnf install wsdd
Before starting the service, you should disable IPv6 support, as this can cause connection problems with Windows in the future. To do this, open the file /etc/default/wsdd and add the --ipv4only option to the WSDD_PARAMS variable:
/etc/default/wsddWSDD_PARAMS="--ipv4only"
Note, that you need root privileges to edit files in the /etc/ directory. Then start the wsdd service and add it to the autoload:
sudo systemctl enable --now wsdd
After this, open the Network section in the Explorer on windows machine and make sure everything works:
If despite these settings you still can't find your SMB server in Windows, or you get an error, you can try to connect to remote host directly. To do this, type two slashes and its IP address in the address bar. For example, //192.168.124.35:
If for some reason something still doesn't work, you can check what went wrong using the Event Viewer utility in Windows. It can be launched from the main menu:
Here you need to open Applications and Services Logs, then Microsoft, then Windows, and in this list, find SMBClient. Here are the SMB client logs, by analyzing which you can understand what went wrong:
Wrapping Up
In this article, we looked at how to mount a Samba share in Linux and Windows. If you want to mount such a folder permanently, look at the article on mounting Windows folders, everything works similarly there as there is used the same SMB protocol.