Introduction
In a local network (LAN), file sharing between computers is a common need — especially when you need to exchange data between Linux and Windows systems.
Samba on Linux allows you to create shared folders easily, supporting user authentication and flexible read/write permissions.
In the previous article, we already installed Samba on Ubuntu. In this guide, you’ll learn how to create a shared folder with read and write (R/W) access, and allow Windows clients to connect using a specific user account.
Create a Samba User Account
Recent versions of Windows no longer allow access to shared folders without authentication.
Therefore, we need to create a dedicated user account for Samba:
sudo adduser samba_every
sudo smbpasswd -a samba_every
- adduser samba_every: creates a new system user named
samba_every. - smbpasswd -a samba_every: enables this account in Samba and sets its password.
Create the Shared Folder
Let’s create the shared directory at /srv/samba/share:
sudo mkdir -p /srv/samba/share
sudo chown samba_every:samba_every /srv/samba/share
sudo chmod 2770 /srv/samba/share
Explanation:
- chown: assigns ownership of the folder to user and group
samba_every. - chmod 2770: allows the owner and group to read/write, and keeps group ownership for newly created files (the
2bit sets the “setgid” flag).
Edit the Samba Configuration File
Open the main Samba configuration file:
sudo nano /etc/samba/smb.conf
Here, verify or add the following sections: [global] and your new share definition.
Minimal [global] section:
[global] security = user map to guest = Bad User
- security = user: enables user-based authentication (default in Samba 4, but recommended to state explicitly).
- map to guest = Bad User: if someone enters an invalid username or password, Samba maps them as a guest instead of denying access immediately.
Shared Folder Section [share]:
[share] path = /srv/samba/share writable = yes browseable = yes valid users = samba_every create mask = 0660 directory mask = 0770
Parameter explanation:
| Parameter | Description |
|---|---|
path | Path to the actual folder being shared. |
writable | Allows writing data to the folder. |
browseable | Makes the folder visible when browsing the network. |
valid users | Specifies who can access the share. |
create mask | Default permissions for new files (owner and group can read/write). |
directory mask | Default permissions for new directories. |
Restart Samba Services
After saving your configuration, restart Samba to apply changes:
sudo systemctl restart smbd
Check for syntax errors:
testparm
If you see Loaded services file OK, your configuration is valid.
Access from Windows
From a Windows machine, open File Explorer and type the following path:
\\<your-Ubuntu-IP-address>\share
Example:
\\192.168.1.10\share
When prompted for login credentials, enter:
- Username:
samba_every - Password: the password you set earlier
You can now read, write, and edit files directly in this shared folder from Windows.
Optional: Allow Multiple Users to Write
If multiple users need to write to the same folder, you can enable group write access:
sudo chgrp -R sambashare /srv/samba/share sudo chmod -R g+rw /srv/samba/share
This ensures that all users in the sambashare group have read/write access without permission conflicts.
Conclusion
With just a few simple steps, you’ve successfully created a Samba shared folder with read/write access, secure and convenient for your local network.
In upcoming guides, we’ll extend this setup to public shares or group-based permissions for more advanced management.
Read more
- Samba – Part 3 – Set Up Samba with Separate Read/Write Access for Each User
- Samba – Part 2 – Share a Folder with Read and Write Access in LAN
- Samba – Part 1 – Install Samba Server on Linux Ubuntu | Debian
- How to Install Windows Server 2025 on Hyper-V (Step-by-Step Tutorial)
- How to Install Android on Hyper-V using BlissOS on Windows