Samba Share Setup Guide - Configure Linux File Sharing

Learn how to set up Samba shares on Linux. This guide covers creating users, groups, setting permissions, and configuring Samba for read/write access for individuals or groups.

Samba Share Configuration

Samba File Sharing Setup

This guide provides instructions on setting up Samba shares on a Linux system. Samba is a crucial tool for enabling file and print services between Linux/Unix and Windows clients. We will cover user creation, group management, directory permissions, and various configuration options for your Samba shares.

External Resources for Samba

For more in-depth information and advanced configurations, refer to these external resources:

Setting Up Samba Shares

Follow these steps to configure your Samba shares:

1. Create a System User

First, create a system user that will own the shared files. This user does not necessarily need a login shell.

useradd --system me
chown -R me /disk/share

2. Create a Group for Shared Access

Create a Linux group that will be used to manage access to the share.

sudo groupadd mygroup

3. Add User to the Group

Add the created user to the new group.

sudo usermod -aG mygroup me

4. Set Directory Permissions

Ensure the shared directory is owned by the group and has the setgid bit set, which makes new files and subdirectories inherit the group ownership.

chgrp -R mygroup /disk/share
chmod g+s /disk/share

5. Configure Samba Share Options

Edit your Samba configuration file (typically /etc/samba/smb.conf) to define your share. Here are common configurations:

a) Allow All Users Read and Write Access

This configuration makes the share publicly accessible with read and write permissions.

[share]
  path = /disk/share
  writeable = yes
  browseable = yes
  public = yes
  create mask = 0644
  directory mask = 0755
  force user = me

b) Allow Group Members Read and Write Access

This configuration restricts write access to users who are members of the specified group.

[share]
  path = /disk/share
  valid users = @mygroup
  writeable = yes
  browseable = yes
  create mask = 0644
  directory mask = 0755
  force user = me

c) Allow Only a Specific User Read and Write Access

To allow only a specific user, you first need to set a Samba password for that user.

sudo smbpasswd -a me

Then, configure the share to be accessible only by that user:

[share]
  path = /disk/share
  valid users = me
  writeable = yes
  browseable = yes
  create mask = 0644
  directory mask = 0755
  force user = me

Additional Samba Share Examples

Here are more examples demonstrating different access control scenarios:

Read to Some, Write to Some

[share]
  comment = Ubuntu Share
  path = /your/samba/share
  browsable = yes
  guest ok = yes
  read only = no
  read list = guest nobody
  write list = user1 user2 user3
  create mask = 0755

Read to All, Write to Some

[share]
  comment = Ubuntu Share
  path = /your/samba/share
  browsable = yes
  guest ok = yes
  read only = yes
  write list = user1 user2 user3
  create mask = 0755

After making changes to smb.conf, remember to restart the Samba services for the changes to take effect:

sudo systemctl restart smbd nmbd