Restricting Writing Access on a Samba Server: A User's Guide

Abstract: Configure read only = yes in smb.conf to prevent network clients from modifying, deleting, or creating files on a Samba share.

Created: 2026-09-19 by
To restrict writing access on a Samba server, you must configure the read only parameter within your share definitions in /etc/samba/smb.conf. Setting this directive to yes ensures that all clients can read files but cannot modify, delete, or create new content. This approach provides a simple, effective layer of security for public directories where data integrity is critical and write permissions are unnecessary for most users.

Understanding Read-Only Shares

Samba allows administrators to define granular access controls for shared resources. The primary mechanism for preventing modifications is the read only option. When enabled, the server treats the share as immutable from the perspective of network clients. This is distinct from file system permissions; even if the underlying Linux directory has 777 permissions, the Samba configuration takes precedence for network access. This method is ideal for distributing software updates, serving documentation, or hosting media libraries where users should not alter the source files. It prevents accidental deletions by careless users and protects against malicious changes. By enforcing read-only access at the protocol level, you reduce the attack surface and simplify permission management across different operating systems.

Configuring smb.conf

The core configuration file for Samba is located at /etc/samba/smb.conf. You will need root privileges to edit this file using a text editor such as nano or vim. Open the file and locate the specific [share_name] section you wish to protect. If the section does not exist, you must create it. Inside the share definition, add or modify the following line:
[my_public_share]
   path = /srv/samba/public
   browseable = yes
   read only = yes
   guest ok = no
The key directive here is read only = yes. This tells the Samba daemon to reject any write operations, including write, delete, rename, and mkdir. Ensure that you do not use non-standard variations like writable=no, as these may be ignored or cause parsing errors depending on the Samba version. Always use the standard read only syntax for compatibility and clarity. After saving the file, verify the syntax for errors by running:
testparm -s
If the test passes, restart the Samba service to apply the changes:
sudo systemctl restart smbd

Layering with Unix Permissions

While read only = yes handles network-level restrictions, it is best practice to align these with Unix file system permissions. This creates a defense-in-depth strategy. Even if a user bypasses Samba settings through other means, the underlying OS permissions provide a final barrier. For a read-only share, set the directory permissions to allow reading but deny writing for the relevant group or user. For example:
sudo chown -R root:root /srv/samba/public
sudo chmod 755 /srv/samba/public
This ensures that only the owner (root) can write to the directory locally. Network users connecting via Samba will still be blocked by the read only directive, but the local permissions prevent unauthorized local modifications if direct access is granted. This dual-layer approach is robust and recommended for production environments.

Handling Specific User Exceptions

Sometimes, you may need to make a share mostly read-only but allow specific administrators to write. In this case, rely on the valid users and write list directives rather than trying to manipulate the read only flag dynamically.
[secure_share]
   path = /srv/samba/secure
   read only = yes
   valid users = @admins @users
   write list = @admins
Here, read only = yes sets the default state. However, the write list directive overrides this for members of the @admins group. Users in @users can read but cannot write. This is more reliable than attempting complex conditional logic within the global scope. Always ensure that the Unix groups match the Samba group names defined in /etc/group.

Verifying Access Control

After applying your configuration, test the access from a client machine. On a Linux client, you can mount the share and attempt to create a file:
touch /mnt/samba/test_file.txt
You should receive a "Permission denied" error. If the operation succeeds, review your smb.conf for syntax errors or check if another configuration file is overriding your settings. Additionally, monitor the Samba logs at /var/log/samba/log.smbd for detailed information about rejected connections. For related insights on managing Linux services and configurations, see Preserve Order of Closing Services While Shutting Down Linux. Understanding service dependencies helps when restarting Samba during maintenance windows.

Frequently Asked Questions

Can I override read-only access using sudo?

No, read only = yes applies to the Samba daemon's handling of SMB/CIFS requests regardless of the user's local privileges. Even if a user has sudo rights on their local machine, they cannot write to the share unless the Samba configuration explicitly permits it via write list.

What happens if I mix read-only and writable shares?

Samba handles multiple shares independently. You can have one share configured with read only = yes and another with read only = no in the same smb.conf file. Each share operates based on its own section definitions, allowing flexible access control strategies.

Does read-only affect symbolic links?

Yes, clients cannot modify the target of a symbolic link within a read-only share. They also cannot create new symbolic links if the share is strictly read-only. This prevents potential symlink attacks where users might try to redirect writes to sensitive system directories.

How do I troubleshoot persistent write access?

Check for conflicting directives in the global section of smb.conf. If read only = no is set globally, it might override share-specific settings unless explicitly overridden. Use testparm to see the effective configuration and ensure your share section comes after any global defaults.

Is there a performance impact of read-only shares?

There is negligible performance impact. The Samba daemon simply checks the access control list for write operations and rejects them immediately. This check is lightweight and does not involve additional disk I/O or processing overhead compared to writable shares.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More