For the complete documentation index, see llms.txt. This page is also available as Markdown.

37.2 Samba File Sharing

Samba Overview

Samba is a free software reimplementation of the Server Message Block (SMB) and Common Internet File System (CIFS) protocols. Its core objective is to achieve interoperability between UNIX systems and Windows network environments.

In terms of architecture, smbd (file and print service daemon) and nmbd (NetBIOS name service daemon) work together: smbd handles file sharing and print service requests, while nmbd provides NetBIOS name resolution and network browsing services.

Samba requires the following ports to be allowed through the firewall:

Protocol
Port
Service
Requirement

TCP

139

NetBIOS Session Service

Required only when using the SMBv1 (NT1) protocol

UDP

137

NetBIOS Name Service

Required only when using the SMBv1 (NT1) protocol

UDP

138

NetBIOS Datagram Service

Required only when using the SMBv1 (NT1) protocol

TCP

445

SMB over TCP

Always required

If min protocol = SMB2 or higher is configured, only TCP 445 needs to be opened.

Samba author Andrew Tridgell had to rename the project in its early days because the original name "smbserver" was claimed as a trademark by Syntax (whose commercial product TotalNet Advanced Server held the trademark for that name). The new name was found by searching the system dictionary for words containing the letters s, m, b in sequence using the Unix command grep -i '^s.*m.*b' /usr/share/dict/words, and thus "Samba" was born. It should be noted that "samba" also means "samba dance" in Portuguese and English, which is a coincidental resemblance.

Installing Samba

There are two main ways to install Samba:

  • Install using pkg:

# pkg install samba423
  • Or install using Ports:

# cd /usr/ports/net/samba423/
# make install clean
  • View installation information:

Basic Configuration

Editing the Samba Configuration File

Create the Samba configuration file /usr/local/etc/smb4.conf, write the following content and save:

Configuration item descriptions:

Configuration Item
Description

[global]

Global configuration section, applies to all shares

min protocol = SMB2

Restricts the minimum supported protocol to SMB2, allowing newer versions of Windows to access

[test_share]

Defines the share name

comment = root's stuff

Description of the share; this text is displayed when browsing shares in Windows Explorer

path = /root

The actual path of the share is /root; sharing this directory is not recommended in production environments

valid users = ykla

Only allows user ykla to access the Samba server

public = no

Does not allow anonymous access (equivalent to guest ok = no)

browseable = yes

The share can be browsed in Network Neighborhood

writable = yes

Allows clients to write to this directory

printable = no

This share is not a printer share

create mask = 0644

Default permissions for newly created files are 0644, preventing files from being accidentally given execute permission

Directory Permission Adjustment

Prepare the directory and adjust directory permissions:

At this point, the permissions of the directory /home/ykla/test should be as follows:

Place some files in the directory /home/ykla/test for testing.

User Management

For security reasons, avoid creating a Samba root user.

Samba only recognizes accounts that have been added to its internal database, so FreeBSD user accounts must be mapped to the Samba account database before Windows clients can access shares. pdbedit(8) supports user databases based on multiple backends such as smbpasswd, ldap, nis+, and tdb. You can use pdbedit(8) to map the existing FreeBSD user account ykla to Samba:

The password set here can be different from the FreeBSD user account password; it is only used to authenticate with the Samba server.

Starting the Samba Service

  • Set the Samba service to start at boot:

  • Start the Samba service

  • View the running status of the Samba service:

Samba includes three daemons: nmbd, smbd, and winbindd. Among them, nmbd and smbd are managed by samba_server_enable, while winbindd must be enabled separately via winbindd_enable (not required in this example).

Using the Samba Share Service

  • To access the shared folder on a Windows system: press Windows logo key + R simultaneously to open the "Run" dialog, and enter the following UNC path (replace the example IP address with the actual value):

Windows accessing network shared resources

Enter the Samba username ykla and its password in the credential prompt:

Entering Samba username

After successful connection, you can see the shared item name "test_share".

Connecting to Samba

Click on the shared item "test_share" to browse the files:

Connecting to Samba

Both read and write operations work normally.

Domain Member Configuration

System Parameter Optimization

Kerberos Authentication

Configuring Name Services

Configure NSS so that the system resolves user records through local files and Winbind in order:

Configure NSS so that the system resolves group records through local files and Winbind in order:

Samba Main Configuration File

The create mode and force create mode items in the testshare share section above are used to adjust the permissions of newly created files during actual operation and are optional configurations:

Domain Management

Service Auto-Start Configuration

Set the Winbind service to start automatically at boot:

Join the host to the Active Directory domain without updating DNS:

Kerberos Authentication Verification

Winbind Service Verification

If the wbinfo command returns an error, you can restart the Samba service and verify again:

Shared Directory Configuration

If you only want the owner to read and write, and the group to only read, you can execute:

If you only want the owner to read and write, and both the group and others to have no access, you can execute:

Troubleshooting

Samba log files are located by default in the /var/log/samba4 directory, with filenames prefixed with log. followed by the client hostname. These can be used to troubleshoot connection and authentication issues.

References

Last updated