| |

LFCE 68 ๐Ÿง Samba โ€” Installation and Config

โฑ๏ธ Estimated read: 11 min | |

Samba is the Linux implementation of the SMB/CIFS protocol, the file-sharing protocol that Windows clients use. The previous chapter covered NFS, which shares files between Unix-like systems; Samba shares files with Windows, macOS, and Linux clients that speak the SMB protocol. The LFCE exam objectives include providing SMB/CIFS shares to clients using Samba . The installation is a package manager command, but the configuration requires understanding the smb.conf structure, the [global] section that controls the server’s identity and security mode, and the share sections that define the directories that clients can access.

The configuration file is /etc/samba/smb.conf. It is divided into two types of sections: the [global] section that applies to the entire server, and the share sections that define individual directories. The workgroup parameter in the global section matches the Windows workgroup name. The security parameter determines how clients authenticate, with user being the default for a standalone server that authenticates against the local Samba user database . The testparm command validates the configuration before the service is restarted.

Key point: Samba shares are defined by a section name in square brackets, followed by the path to the directory and the access options. The read only = no option makes the share writable, and the guest ok = yes option allows access without a password . The smbpasswd -a command adds a user to the Samba password database, which is separate from the Linux user database. Without a Samba user, the client cannot authenticate even if the Linux user exists.


Why Samba configuration requires explicit user management

The authentication problem.

Samba does not use the Linux password database directly for SMB authentication. It maintains its own user database, typically stored in the tdbsam backend. The smbpasswd -a <user> command adds a user to this database and prompts for the SMB password . The Linux user account must exist before the Samba user is created, but the passwords are separate. A client that authenticates with the SMB password is mapped to the Linux user, and the file permissions on the share are evaluated against that user’s UID and GID.

The workgroup problem.

The workgroup parameter in the [global] section must match the Windows workgroup or domain that the clients belong to. If the workgroup names do not match, the clients may not discover the server in the network neighborhood, though they can still connect by IP address or hostname . The netbios name parameter sets the name that the server advertises on the network; if it is not set, Samba uses the hostname.

The share-permission problem.

The read only = no option makes the share writable from Samba’s perspective, but the Linux file permissions must also allow writing. The directory must be owned by a user or group that has write access, and the Samba user must be a member of that group or the owner . The create mask and directory mask options set the permissions for new files and directories created through the share.


a. Installing the packages

The Samba server package is named samba on Debian, Ubuntu, RHEL, and Fedora. The client utilities are in the samba-client or smbclient package.

# Debian / Ubuntu
sudo apt update
sudo apt install samba

# RHEL / Rocky / Fedora
sudo dnf install samba

# Verify the installation
smbd --version
# Output: Version 4.x.x

The smbd daemon is the SMB file-sharing service. The nmbd daemon provides NetBIOS name resolution, which is optional for modern clients that use DNS. The service is managed through systemctl as smbd and nmbd .


b. The global section and the share definition

The [global] section sets the server’s identity and security mode. The share sections define the directories that clients can access.

# /etc/samba/smb.conf
[global]
    workgroup = EXAMPLE
    server string = Samba Server
    security = user
    passdb backend = tdbsam
    log file = /var/log/samba/%m.log
    max log size = 1000

[share]
    comment = Shared Directory
    path = /srv/samba/share
    browsable = yes
    guest ok = yes
    read only = no
    create mask = 0755

The workgroup matches the Windows workgroup. The security = user mode requires clients to authenticate with a username and password. The passdb backend = tdbsam stores the Samba passwords in a TDB database. The log file parameter uses the %m variable, which expands to the client’s NetBIOS name, so each client has its own log file .

The [share] section defines a share named share. The path is the directory to share. The browsable = yes option makes the share visible in the Windows network browser. The guest ok = yes option allows clients to connect without a password. The read only = no option makes the share writable. The create mask = 0755 option sets the permissions for new files .

The directory must be created and the permissions set before the share works.

# Create the directory
sudo mkdir -p /srv/samba/share

# Set ownership to the Samba user or group
sudo chown nobody:nogroup /srv/samba/share
sudo chmod 777 /srv/samba/share

The chmod 777 is appropriate only for a guest-accessible share. For an authenticated share, the directory should be owned by the user or group that the Samba users belong to, with the appropriate permissions .


c. Creating Samba users and validating the configuration

A Samba user must be created for each user that authenticates to the share. The Linux user account must exist first.

# Create a Linux user without a login shell
sudo useradd -M -s /usr/sbin/nologin alice

# Add the user to the Samba database
sudo smbpasswd -a alice
# New SMB password: <password>
# Retype new SMB password: <password>

The useradd -M -s /usr/sbin/nologin command creates a Linux user without a home directory and without a login shell, which is appropriate for a user that only accesses Samba . The smbpasswd -a command adds the user to the Samba database and prompts for the password. The password is separate from the Linux password.

The testparm command validates the smb.conf syntax before the service is restarted.

# Validate the configuration
sudo testparm
# Output: Load smb config files from /etc/samba/smb.conf
#         Loaded services file OK.

# Restart the service
sudo systemctl restart smbd
sudo systemctl enable smbd

The testparm command parses the configuration and reports syntax errors. It should be run after every change . The systemctl restart smbd command applies the configuration, and the systemctl enable smbd command configures the service to start at boot.


Complete Example Session

# ============================================
# PART 1: INSTALL SAMBA
# ============================================
sudo apt install samba

# ============================================
# PART 2: BACK UP THE DEFAULT CONFIGURATION
# ============================================
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

# ============================================
# PART 3: CONFIGURE THE GLOBAL SECTION
# ============================================
sudo tee /etc/samba/smb.conf > /dev/null <<'EOF'
[global]
    workgroup = EXAMPLE
    server string = Samba Server
    security = user
    passdb backend = tdbsam
    log file = /var/log/samba/%m.log
    max log size = 1000
EOF

# ============================================
# PART 4: DEFINE THE SHARE
# ============================================
sudo tee -a /etc/samba/smb.conf > /dev/null <<'EOF'

[share]
    comment = Shared Directory
    path = /srv/samba/share
    browsable = yes
    guest ok = no
    read only = no
    create mask = 0755
EOF

# ============================================
# PART 5: CREATE THE DIRECTORY
# ============================================
sudo mkdir -p /srv/samba/share
sudo chown alice:alice /srv/samba/share
sudo chmod 755 /srv/samba/share

# ============================================
# PART 6: CREATE A SAMBA USER
# ============================================
sudo useradd -M -s /usr/sbin/nologin alice
sudo smbpasswd -a alice
# Enter the SMB password when prompted

# ============================================
# PART 7: VALIDATE THE CONFIGURATION
# ============================================
sudo testparm
# Output: Loaded services file OK.

# ============================================
# PART 8: START AND ENABLE THE SERVICE
# ============================================
sudo systemctl restart smbd
sudo systemctl enable smbd

# ============================================
# PART 9: OPEN THE FIREWALL
# ============================================
sudo firewall-cmd --permanent --add-service=samba
sudo firewall-cmd --reload
# Or on Debian: sudo ufw allow samba

# ============================================
# PART 10: TEST FROM A CLIENT
# ============================================
# On a client:
# smbclient -L //server -U alice
# smbclient //server/share -U alice
# Or mount: sudo mount -t cifs //server/share /mnt -o user=alice

The ten parts demonstrate the complete Samba setup: installation, backup, global configuration, share definition, directory creation, user creation, validation, service start, firewall, and client test. The critical verification is Part 7: testparm confirms that the configuration is syntactically valid before the service is restarted.


Quick Reference

Installation Packages

DistributionPackage
Debian / Ubuntusamba
RHEL / Rocky / Fedorasamba

Key smb.conf Parameters

ParameterSectionPurpose
workgroup[global]Windows workgroup name
security[global]Authentication mode (user, ads)
passdb backend[global]Password database (tdbsam)
pathShareDirectory to share
read onlyShareWrite access (no for writable)
guest okSharePasswordless access
browsableShareVisible in network browser
create maskSharePermissions for new files

Commands

CommandPurpose
testparmValidate configuration
smbpasswd -a <user>Add Samba user
smbpasswd <user>Change Samba password
pdbedit -LList Samba users
systemctl restart smbdApply configuration
smbclient -L //serverList shares

Firewall

SystemCommand
firewalldfirewall-cmd --add-service=samba
ufwufw allow samba

Best Practices

โœ… Do This:

# Validate before restarting
testparm                                                      # โœ…

# Create Linux user without login shell
useradd -M -s /usr/sbin/nologin alice                         # โœ…

# Add Samba user
smbpasswd -a alice                                            # โœ…

# Set the workgroup to match the clients
workgroup = EXAMPLE                                           # โœ…

# Use security = user for standalone servers
security = user                                               # โœ…

# Set the directory permissions
chown alice:alice /srv/samba/share && chmod 755 /srv/samba/share # โœ…

โŒ Don’t Do This:

# Forget to create the Samba user
# The client cannot authenticate                              # โŒ

# Use guest ok = yes for sensitive data
guest ok = yes                                                # โŒ

# Forget to restart smbd after configuration changes
systemctl restart smbd                                        # โœ… (do this)

# Use security = share (removed in Samba 4)
security = share                                              # โŒ

# Ignore testparm
systemctl restart smbd    # Syntax error prevents start       # โŒ

Common Pitfalls

PitfallWhy It HappensFix
Client cannot authenticateNo Samba usersmbpasswd -a <user>
Share not visiblebrowsable = no or workgroup mismatchSet browsable = yes; match workgroup
Cannot write despite read only = noDirectory permissionschown and chmod the directory
Service fails to startSyntax error in smb.conftestparm reports the error
Firewall blocks connectionSamba ports not openfirewall-cmd --add-service=samba

Real-World Examples

1. Install Samba

apt install samba

2. Global section

[global]
workgroup = EXAMPLE
security = user
passdb backend = tdbsam

3. Read-only share

[readonly]
path = /srv/samba/readonly
read only = yes
browsable = yes

4. Writable share

[share]
path = /srv/samba/share
read only = no
guest ok = no

5. Guest share

[public]
path = /srv/samba/public
guest ok = yes
read only = no

6. Create Samba user

useradd -M -s /usr/sbin/nologin alice && smbpasswd -a alice

7. Validate configuration

testparm

8. Restart service

systemctl restart smbd && systemctl enable smbd

9. List shares

smbclient -L //localhost -U alice

10. Mount from client

mount -t cifs //server/share /mnt -o user=alice

Visual

Samba Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  SAMBA PROVIDES SMB/CIFS SHARES TO WINDOWS CLIENTS           โ”‚
โ”‚                                                              โ”‚
โ”‚  Windows Client                                              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                 โ”‚
โ”‚  โ”‚ Explorerโ”‚                                                 โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜                                                 โ”‚
โ”‚       โ”‚ SMB (TCP 445)                                        โ”‚
โ”‚       โ–ผ                                                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Samba (smbd)                                           โ”‚  โ”‚
โ”‚  โ”‚                                                        โ”‚  โ”‚
โ”‚  โ”‚ [global]                                               โ”‚  โ”‚
โ”‚  โ”‚   workgroup = EXAMPLE                                  โ”‚  โ”‚
โ”‚  โ”‚   security = user                                      โ”‚  โ”‚
โ”‚  โ”‚                                                        โ”‚  โ”‚
โ”‚  โ”‚ [share]                                                โ”‚  โ”‚
โ”‚  โ”‚   path = /srv/samba/share                              โ”‚  โ”‚
โ”‚  โ”‚   read only = no                                       โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                             โ”‚                                โ”‚
โ”‚                             โ–ผ                                โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Linux Filesystem                                       โ”‚  โ”‚
โ”‚  โ”‚ /srv/samba/share                                       โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

smb.conf Structure

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  GLOBAL SECTION AND SHARE SECTIONS                           โ”‚
โ”‚                                                              โ”‚
โ”‚  [global]                                                    โ”‚
โ”‚  โ”œโ”€โ”€ workgroup = EXAMPLE                                     โ”‚
โ”‚  โ”œโ”€โ”€ security = user                                         โ”‚
โ”‚  โ”œโ”€โ”€ passdb backend = tdbsam                                 โ”‚
โ”‚  โ””โ”€โ”€ log file = /var/log/samba/%m.log                        โ”‚
โ”‚                                                              โ”‚
โ”‚  [share]                                                     โ”‚
โ”‚  โ”œโ”€โ”€ comment = Shared Directory                              โ”‚
โ”‚  โ”œโ”€โ”€ path = /srv/samba/share                                 โ”‚
โ”‚  โ”œโ”€โ”€ browsable = yes                                         โ”‚
โ”‚  โ”œโ”€โ”€ guest ok = no                                           โ”‚
โ”‚  โ””โ”€โ”€ read only = no                                          โ”‚
โ”‚                                                              โ”‚
โ”‚  [another-share]                                             โ”‚
โ”‚  โ””โ”€โ”€ ...                                                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

User Creation Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  TWO USER DATABASES                                          โ”‚
โ”‚                                                              โ”‚
โ”‚  Linux user database:                                        โ”‚
โ”‚  โ””โ”€โ”€ useradd -M -s /usr/sbin/nologin alice                   โ”‚
โ”‚                                                              โ”‚
โ”‚  Samba user database:                                        โ”‚
โ”‚  โ””โ”€โ”€ smbpasswd -a alice                                      โ”‚
โ”‚      โ””โ”€โ”€ prompts for SMB password                            โ”‚
โ”‚                                                              โ”‚
โ”‚  The client authenticates against the Samba database.        โ”‚
โ”‚  The file access is evaluated against the Linux UID/GID.     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
Packagesamba
Configuration/etc/samba/smb.conf
Daemonsmbd
Global section[global]
Share section[share]
Share pathpath = /srv/samba/share
Write accessread only = no
Guest accessguest ok = yes
Security modesecurity = user
Password databasepassdb backend = tdbsam
Add Samba usersmbpasswd -a <user>
Validate configtestparm
Servicesystemctl restart smbd
Firewallfirewall-cmd --add-service=samba

Key takeaways:

  • Samba shares files with Windows clients using SMB/CIFS. The smbd daemon handles the protocol, and the /etc/samba/smb.conf file defines the server’s identity and the shares .
  • The [global] section sets the workgroup and security mode. The workgroup matches the Windows workgroup, and security = user requires clients to authenticate with a Samba username and password .
  • Each share is a section with a path and access options. The read only = no option makes the share writable, and guest ok = yes allows passwordless access. The browsable = yes option makes the share visible in the network browser .
  • Samba users are separate from Linux users. The smbpasswd -a <user> command adds a user to the Samba database. The Linux user must exist first, but the passwords are separate .
  • testparm validates the configuration. It parses the smb.conf file and reports syntax errors before the service is restarted. It should be run after every change .
  • The directory permissions must allow the Samba user to write. The read only = no option is not sufficient if the Linux permissions deny write access. The directory must be owned by the user or group that the Samba user belongs to.

Remember: Samba is the SMB/CIFS server. The [global] section defines the workgroup and the security mode. Each share section defines a directory and its access options. The Samba user is created with smbpasswd -a, and the Linux user must exist first. The testparm command validates the configuration, and the smbd service serves the shares. The firewall must permit the SMB traffic. Configure the global section, define the shares, create the users, validate, restart, and test from a client.


Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!