This episode builds a production-ready [data] share with path=/srv/data, browseable=yes, and writable=yes, plus owner mapping via force user and force group. You also understand the two stacked permission layers — Linux filesystem vs Samba share options — and the role of valid users and write list in restricting access.

The basic configuration from episode 3 already created your first share. In episode 4 we go up a level: building a data share that's truly used in production — with correct owner mapping and an honest understanding of how the two permission layers work together. This is the most important episode for avoiding the "why is the file I wrote owned by a strange user?" frustration that haunts every beginner Samba administrator.
A data directory usually has different characteristics from a public share: it needs read-write access, is managed by a team, and has clear ownership. Prepare the directory and its share:
sudo mkdir -p /srv/data
sudo chown root:staff /srv/data
sudo chmod 2770 /srv/data
ls -ld /srv/datachmod 2770 turns on setgid (bit 2) so new files inherit the staff group, and gives full access only to owner/group. This is the foundation of collaboration: all staff members can read-write without trampling each other's rights. Here's the share configuration:
[data]
path = /srv/data
browseable = yes
writable = yes
valid users = @staff
force user = arman
force group = staff
create mask = 0660
directory mask = 2770Let's break down each line:
path = /srv/data: the directory being shared.browseable = yes: the share appears in the list when browsing the network.writable = yes: allow write operations from clients (synonym of read only = no).valid users = @staff: only members of the staff group may access (the @ prefix denotes a group).force user = arman: every file created by a client becomes owned by user arman.force group = staff: every file inherits the staff group.create mask/directory mask: force file (0660) and directory (2770) permissions to stay aligned with the collaboration design.The classic problem: a Windows client connects as arman, but the files it creates end up owned by another user because Samba uses the connect identity when writing. force user/force group standardizes ownership — no matter who logs in, files always end up owned by arman and the staff group. This isn't a "hack"; it's a standard pattern in collaborative shares so filesystem permissions stay predictable. Use it wisely: force user overrides real ownership, so don't point it at root without a strong reason.
The options in the share section — valid users, writable, read only, write list — are the first gate. Samba checks these before processing any file operation. valid users = @staff means users outside staff can't even open the share, regardless of their filesystem permissions.
Even if the Samba layer is passed, the Linux kernel still checks filesystem permissions (mode bits, owner, group, and ACLs). These are two stacked gates: access = pass share options AND pass filesystem permissions. If either one denies, the operation fails — often without a clear error message on the client side.
klien --> valid users? --> writable? --> filesystem permission? --> OKA real example: writable = yes in the share, but the /srv/data directory is chmod 755 and owned by root. User arman can open the share but fails to create files. You get an "Access denied" error in Windows Explorer even though "the Samba config is correct". This is exactly the case where testparm doesn't help — the problem is in the second layer.
Sometimes you want everyone to be able to read, but only some to write. That's where write list works together with read only:
[data]
path = /srv/data
read only = yes
write list = @editors, budiread only = yes: baseline — all users are read-only.write list = @editors, budi: exceptions — the editors group and user budi may write.This is the least privilege pattern we'll emphasize again in episode 15: grant the minimum capability needed, then open up explicitly. Compare:
valid users → determines who may enter the share.write list → determines who may write among those already admitted.read only/writable → the share-wide default write access.Tip
Always combine this with a supporting filesystem. If write list allows budi to write, make sure /srv/data also grants write access to budi at the filesystem level (through the same group, for example). Share options and the filesystem must be designed together — not tested partially. After editing, validate with testparm and reload (episode 3).
sudo -u <user> touch /srv/data/test.force user/force group.chmod 2770 on the parent directory so new files stay in the right group; directory mask also needs the setgid bit.valid users blocks too much: forgetting the @ prefix on a group causes a Failed to find a POSIX uid error in the logs — write @staff, not staff.Test with the command-line client (with a user registered in episode 5):
smbclient //localhost/data -U arman -c "mkdir testdir; ls; exit"
ls -ld /srv/data/testdirIf testdir appears and is owned by arman:staff, both permission layers are working correctly. This is a moment worth a small celebration: your first production share is alive.
Key takeaways:
[data] share with path, browseable, writable forms a production-ready basic share.force user/force group standardize ownership of client-created files.valid users determines who enters; read only + write list determines who writes.sudo -u <user> touch) before blaming the Samba config.In episode 5 next, we'll cover user management & smbpasswd: synchronizing system users with the Samba password database, smbpasswd -a, pdbedit -L, the tdbsam storage format, username map for aliases, and account flags. After this episode, you can create users who can actually log into your shares.