To access files from a Windows 10 machine using File Explorer, you must install the Samba suite on your Ubuntu system, configure shared directories with appropriate permissions, and ensure the firewall allows SMB traffic. Once the service is running, you can map the network drive or browse directly to the server's IP address in Windows Explorer by entering the correct credentials for a Samba user.
Installing Samba on Ubuntu
The first step involves installing the necessary software packages that enable file sharing over the network. Ubuntu uses the
apt package manager to handle these installations efficiently. Open your terminal window and execute the following command to update your package list and install Samba along with the common Internet filesystem utilities:
sudo apt update
sudo apt install samba smbclient cifs-utils
This installation provides the
smbd daemon which handles the file sharing protocol and the
nmbd daemon which manages name resolution. The
cifs-utils package is also helpful if you need to mount CIFS shares later, though it is primarily needed on the client side. After the installation completes, verify that the services are installed correctly by checking their status. You can do this by running
systemctl status smbd. If the service is inactive, start it immediately with
sudo systemctl start smbd and enable it to start on boot with
sudo systemctl enable smbd.
Configuring Shared Directories
Samba configuration is managed through the
/etc/samba/smb.conf file. Before editing, it is wise to create a backup of the original configuration file so you can revert changes if something goes wrong. Run
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak. Next, open the configuration file in a text editor like
nano or
vim using sudo privileges.
You need to define a new share section at the end of the file. For example, to share a folder named
shared_files located in your home directory, add the following block:
[shared_files]
comment = Shared Files from Ubuntu
path = /home/yourusername/shared_files
browseable = yes
read only = no
valid users = yourusername
Replace
yourusername with your actual Linux username. The
browseable option ensures the share appears when browsing the network, while
read only = no allows write access. It is crucial that the underlying Linux directory permissions allow the user to read and write. Create the directory if it does not exist using
mkdir ~/shared_files and set permissions with
chmod 755 ~/shared_files. This ensures the owner has full control while others have read access, aligning with the Samba configuration.
Setting Up Samba Users
A critical security feature of Samba is that it maintains its own separate password database, distinct from the Linux system passwords. You must create a Samba user account for each Linux user who needs access. Use the
smbpasswd command to add a user and set a password:
sudo smbpasswd -a yourusername
You will be prompted to enter and confirm a new password. This password is used specifically for authenticating via the network share. Note that adding a user to the Samba database does not automatically enable them; they must be enabled explicitly. If you encounter issues logging in, ensure the user is enabled by running sudo smbpasswd -e yourusername. Restart the Samba services to apply all configuration changes:
sudo systemctl restart smbd nmbd
Firewall Configuration
Ubuntu typically runs with UFW (Uncomplicated Firewall) enabled, which blocks incoming connections by default. You must allow Samba traffic through the firewall for Windows machines to discover and connect to the server. Allow the Samba profile by running:
sudo ufw allow samba
If you prefer more granular control, you can allow specific ports. Samba uses port 445 for direct hosting over TCP/IP and port 139 for NetBIOS sessions. You can allow these manually with sudo ufw allow 445/tcp and sudo ufw allow 139/tcp. Verify the rules are active by running sudo ufw status. Ensure that your Windows machine and Ubuntu machine are on the same local network subnet for optimal discovery and performance.
Accessing from Windows 10
On your Windows 10 machine, open File Explorer. In the address bar, type the UNC path to the Ubuntu server. The format is \\IP_ADDRESS_OF_UBUNTU\shared_files. Replace IP_ADDRESS_OF_UBUNTU with the actual IP address of your Ubuntu machine, which you can find by running hostname -I in the Ubuntu terminal. Press Enter, and a login prompt should appear. Enter the Linux username and the Samba password you created earlier.
If you wish to make this connection persistent, right-click on "This PC" and select "Map network drive." Choose a drive letter, enter the same UNC path, and check "Reconnect at sign-in." This ensures the share is available every time you log into Windows. For troubleshooting connection issues, ensure that Network Discovery is turned on in Windows Control Panel under Network and Sharing Center. Also, verify that the Windows Firewall is not blocking outbound SMB connections.
Frequently Asked Questions
Why can't Windows see my Ubuntu server in the Network tab?
Windows relies on NetBIOS name resolution to discover devices on the local network. Ensure that the nmbd service is running on Ubuntu and that UFW allows UDP ports 137 and 138. Additionally, Windows may require SMB 1.0 support to be enabled for legacy discovery, though using the direct IP path is more reliable and secure.
How do I change the Samba password after creation?
You can change the Samba password at any time using the smbpasswd command without the -a flag. Simply run sudo smbpasswd yourusername in the terminal. You will be prompted to enter the current password and then the new password twice. This updates the internal Samba password database only.
What if I get an "Access Denied" error in File Explorer?
This usually indicates a mismatch between Linux file permissions and Samba settings. Check that the directory owned by the user has appropriate permissions using ls -l ~/shared_files. Also, verify that the valid users directive in smb.conf matches the username you are logging in with. Ensure the Samba user is enabled with smbpasswd -e.
Can I share multiple folders with different permissions?
Yes, you can define multiple sections in smb.conf, each with a unique name, path, and permission settings. For example, one share can be read-only for guests while another requires authentication for writing. Each section operates independently, allowing fine-grained control over network access. Remember to restart the Samba service after making changes.
Is it safe to use Samba on a public Wi-Fi network?
No, Samba does not encrypt data by default, meaning credentials and file contents can be intercepted on unsecured networks. Always use Samba on trusted private networks. If remote access is required, consider setting up a VPN or using SSH tunneling to encrypt the SMB traffic before exposing it to the internet.