Guide: Simple Samba Share with Guest Access (Read-Only)
This guide will help you set up a Samba share on a Linux server that is accessible to everyone on your network without a password, and is read-only. Perfect for sharing public files like manuals, photos, or videos.
What is Samba?
Samba is an open-source software suite that enables Linux/Unix systems to communicate with Windows clients using the SMB/CIFS protocol. In short, it allows your Linux server to function as a Windows file server.
Step 1: Install Samba on your Linux Server
Start by installing Samba. On most Debian/Ubuntu-based systems, you do this as follows:
sudo apt update
sudo apt install samba
For CentOS/RHEL/Fedora:
sudo dnf install samba samba-client samba-common
sudo systemctl enable smb nmb
sudo systemctl start smb nmb
Step 2: Back Up Your Samba Configuration
It's always a good idea to back up the original configuration file before making any changes.
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
Step 3: Create Share Directory and Set Permissions
We will create a new directory that we will share and set the correct Linux permissions so that the 'nobody' (guest) user can read it. Here we use the hypothetical directory /mnt/public_data.
sudo mkdir -p /mnt/public_data
sudo chmod -R 755 /mnt/public_data
sudo chown -R nobody:nogroup /mnt/public_data
- mkdir -p: Creates the directory (and any parent directories).
- chmod -R 755: Grants read, write, and execute permissions to the owner, and read and execute permissions to others (including guests).
- chown -R nobody:nogroup: Sets the owner of the directory to the 'nobody' user and the group to 'nogroup'. This is important for guest access.
Step 4: Edit Samba Configuration File
Open the Samba configuration file (`smb.conf`) with a text editor, for example `nano`:
sudo nano /etc/samba/smb.conf
Adjust Global Settings:
Find the [global] section in the file. Add the following lines or verify that they are present and correctly set. These settings ensure that guest access works.
[global]
workgroup = WORKGROUP
security = user
map to guest = Bad User
guest account = nobody
usershare allow guests = yes
- workgroup = WORKGROUP: Make sure this matches the workgroup of your Windows computers. This is usually 'WORKGROUP'.
- security = user: This is the recommended security mode.
- map to guest = Bad User: Crucial! If a user tries to log in with a name that doesn't exist on the server, they will be mapped to the guest user.
- guest account = nobody: The Unix user used for guest access. 'nobody' is the standard.
- usershare allow guests = yes: Optional, but allows users to create their own shares with guest access.
Add New Share:
Scroll to the end of the `smb.conf` file and add the definition for your new share. Here we use [PublicData] as the name for the share.
[PublicData]
path = /mnt/public_data
read only = yes
guest ok = yes
public = yes
browseable = yes
comment = Public Files (Read-Only Guest Access)
- [PublicData]: The name of your share as it will be visible on the network.
- path = /mnt/public_data: The path to the directory you are sharing on your Linux server.
- read only = yes: Ensures that users cannot modify, delete, or add files.
- guest ok = yes: Allows guest access to this specific share.
- public = yes: An alias for 'guest ok = yes'.
- browseable = yes: The share is visible in the network list.
- comment: An optional description of the share.
Save the file and exit the editor (for nano: Ctrl+O, Enter, Ctrl+X).
Step 5: Restart Samba Service
To apply the changes, you must restart the Samba services:
sudo systemctl restart smbd nmbd
Step 6: Configure Firewall (If Active)
If you have a firewall running (e.g., UFW on Ubuntu), you need to open Samba ports:
sudo ufw allow samba
sudo ufw enable
Or specifically for the ports:
sudo ufw allow 139/tcp
sudo ufw allow 445/tcp
sudo ufw reload
Step 7: Windows Client Configuration (IMPORTANT!)
Modern Windows versions block "insecure guest logons" by default. Even if your Samba is perfectly configured, Windows may still ask for credentials. You need to adjust this on your Windows computer:
1. Press Win + R, type
gpedit.mscand press Enter.
* (If you have Windows Home, gpedit.msc does not work. Use the Registry Editor method below.)
2. Navigate to: Computer Configuration -> Administrative Templates -> Network -> Lanman Workstation.
3. Find the setting "Enable insecure guest logons".
4. Double-click it, select "Enabled" and click OK.
5. Restart your Windows PC.
Alternative for Windows Home (Registry Editor):
1. Press Win + R, type
regeditand press Enter.
2. Navigate to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters
3. Right-click in the right pane, choose New > DWORD (32-bit) Value.
4. Name the new value AllowInsecureGuestAuth.
5. Double-click AllowInsecureGuestAuth and set its Value data to 1.
6. Restart your Windows PC.
Step 8: Test the Share
After restarting your Windows PC, you can test the share:
1. Open File Explorer.
2. Click in the address bar and type the IP address of your Linux server, preceded by two backslashes:
\\192.168.1.100(replace 192.168.1.100 with the actual IP address of your server).
3. Press Enter. You should now see your share 'PublicData' and be able to open it without being prompted for credentials. You can view the files, but not modify them.
Conclusion
You have now set up a Samba share that is accessible to guests and is read-only, which is ideal for sharing public content on your network!