Kahibaro
Discord Login Register

4.5.3 Samba

Understanding Samba in a Linux Environment

Samba is the standard way to share files and printers between Linux/Unix systems and Windows machines using the SMB/CIFS protocol. In a modern network, Samba can act as:

This chapter focuses on practical Samba use for Linux servers in typical small to medium environments.

Core Samba Components and Terminology

Samba is made of several daemons and tools. The most important for basic file sharing are:

Key concepts:

Installing Samba

Package names vary, but typically:

Example (Debian/Ubuntu):

sudo apt update
sudo apt install samba

Example (Fedora/RHEL with DNF):

sudo dnf install samba samba-client

Ensure the main daemons are enabled and running:

sudo systemctl enable --now smb
# on some distros:
sudo systemctl enable --now smbd nmbd

The Samba Configuration File

The main configuration is /etc/samba/smb.conf. It’s divided into:

The file format is ini-like:

[global]
    workgroup = WORKGROUP
    server string = My Samba Server
[public]
    path = /srv/samba/public
    read only = no
    guest ok = yes

After editing, always check for syntax errors:

testparm

If testparm reports no errors, reload Samba:

sudo systemctl reload smb
# or:
sudo systemctl reload smbd

Basic Server Identity and Workgroup Settings

Key [global] options for a simple workgroup server:

[global]
    workgroup = WORKGROUP
    server string = Fileserver
    netbios name = FILESRV01
    # Recommended for modern clients
    security = user
    map to guest = Bad User
    # Use systemd logging; depends on distro
    logging = syslog

Explanation of important parameters:

Creating Basic File Shares

Preparing Directories and Permissions

Before defining a share, create the directory and set appropriate ownership and permissions at the filesystem level.

Example: a public share accessible to everyone on the LAN:

sudo mkdir -p /srv/samba/public
sudo chown nobody:nogroup /srv/samba/public  # Debian-style
sudo chmod 0777 /srv/samba/public

Or a private share for user alice:

sudo mkdir -p /srv/samba/alice
sudo chown alice:alice /srv/samba/alice
sudo chmod 0700 /srv/samba/alice

Samba respects Linux permissions, so setting them correctly is essential.

Example: Public (Guest) Share

Add to /etc/samba/smb.conf:

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

Key options:

Ensure the guest account exists and is mapped (often nobody or guest); some distros handle this automatically.

Example: Private Per-User Share

Assume you want a private share for alice:

  1. Create the directory and set permissions (done earlier).
  2. Create a Samba password for alice:
sudo smbpasswd -a alice
  1. Configure the share:
[alice]
    path = /srv/samba/alice
    browseable = no
    read only = no
    valid users = alice

Now alice authenticates from Windows or Linux clients using her Samba (or system) credentials.

Controlling Access: `valid users`, `write list`

Some useful per-share access controls:

Example: department share:

[dept]
    path = /srv/samba/dept
    browseable = yes
    read only = yes
    valid users = @deptstaff
    write list = @deptadmin

Managing Samba Users and Passwords

Samba usually maintains its own user database, linked to system accounts.

Typical workflow:

  1. Create a system user (if not already present):
sudo useradd -m alice
sudo passwd alice
  1. Add the user to Samba:
sudo smbpasswd -a alice
  1. Enable/disable Samba account:
sudo smbpasswd -e alice  # enable
sudo smbpasswd -d alice  # disable

Samba authenticates users against this Samba password database (or AD/LDAP, in more advanced setups).

Guest Access and the Guest Account

For truly public shares:

Check or set the guest account in smb.conf:

[global]
    guest account = nobody

Ensure the guest account’s filesystem permissions allow read/write as needed.

Integration with Linux Permissions and ACLs

Samba uses underlying filesystem permissions:

When you need complex permission schemes (e.g. multiple groups with different rights), use filesystem ACLs and possibly force group, create mask, and directory mask.

Example to force new files in a share to belong to a particular group:

[projects]
    path = /srv/samba/projects
    read only = no
    valid users = @projteam
    force group = projteam
    create mask = 0660
    directory mask = 0770

Connecting from Clients

From Windows

  1. Open File Explorer.
  2. In the address bar, type \\SERVERNAME or \\IP_ADDRESS.
  3. When prompted, enter username and the Samba password.

To map a network drive:

From Linux

Using smbclient (CLI test):

smbclient -L //server -U alice
smbclient //server/alice -U alice

Permanent mount with cifs in /etc/fstab (requires cifs-utils):

sudo mkdir -p /mnt/alice
echo '//server/alice /mnt/alice cifs username=alice,password=SECRET,iocharset=utf8,vers=3.0 0 0' | sudo tee -a /etc/fstab
sudo mount -a

For security, store credentials in a root-owned file and reference it with credentials=/root/.smbcred instead of embedding passwords in /etc/fstab.

Printer Sharing with Samba (Overview)

Samba can export Linux printers to Windows clients:

  1. Configure the printer on the Linux system (CUPS).
  2. In smb.conf, define a printers share:
[printers]
    comment = All Printers
    path = /var/spool/samba
    browseable = no
    printable = yes
    guest ok = no
    create mask = 0700
  1. Make sure smbd has access to the CUPS system (handled automatically on many distros).

Details of printer drivers and CUPS are handled elsewhere; here, Samba is just making the printer visible to SMB clients.

Joining a Samba Server to Active Directory (Member Server Basics)

In AD environments, Samba servers often act as domain members to:

High-level steps (details vary by distro):

  1. Set the realm and workgroup in [global]:
[global]
    workgroup = EXAMPLE
    realm = EXAMPLE.COM
    security = ADS
    winbind use default domain = yes
  1. Configure DNS and time synchronization with the AD domain.
  2. Join the domain:
sudo net ads join -U Administrator
  1. Use winbind to map AD users/groups to Unix IDs.

Full AD integration involves ID mapping backends and PAM/NSS configuration, which are covered in more advanced materials. For file sharing, the main concept is that Samba can delegate authentication to AD and then enforce access based on AD identities.

Common Security and Hardening Considerations

[global]
    hosts allow = 192.168.1. 127.
    hosts deny = 0.0.0.0/0
[global]
    server min protocol = SMB2
    server max protocol = SMB3

Basic Troubleshooting

Checking Service Status and Logs

Check daemons:

sudo systemctl status smb
# or:
sudo systemctl status smbd nmbd

Common log locations:

Increase log level temporarily for debugging:

[global]
    log level = 3

Remember to reduce it again in production to avoid large logs.

Network and Name Resolution Issues

ping server
smbclient -L //server -N

If names don’t resolve, connect via IP or fix DNS/NetBIOS configuration.

Authentication Problems

getent passwd alice
sudo pdbedit -L | grep alice
sudo smbpasswd alice

Summary

Samba lets a Linux system participate as a first-class SMB file and print server in mixed networks, especially with Windows clients. The essential skills are:

Views: 105

Comments

Please login to add a comment.

Don't have an account? Register now!