Website Vidya
Linux & ServersStep-by-Step Guide

How to Install and Configure Samba on Ubuntu 24.04

Complete guide on how to install and configure Samba on Ubuntu 24.04 LTS. Setup cross-platform Windows file sharing, user authentication, and UFW firewall.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Install and Configure Samba on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

6 min read

Complete guide on how to install and configure Samba on Ubuntu 24.04 LTS. Setup cross-platform Windows file sharing, user authentication, and UFW firewall.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Updating System Packages and Installing Samba
  • Step 2: Backing Up Default Configuration and Tuning smb.conf
Grounded in full engineering runbookWebsiteVidya AI Engine

Samba is the standard open-source software suite that provides seamless file and print services using the Server Message Block (SMB) and Common Internet File System (CIFS) networking protocols. By bridging the architectural gap between POSIX-compliant Unix systems and Microsoft Windows environments, Samba allows an Ubuntu server to function as a powerful central network-attached storage (NAS) appliance or file server accessible to Windows, macOS, and Linux client machines simultaneously.

Whether you are centralizing company document archives, establishing automated backup targets for desktop computers, or streaming multimedia across home networks, Samba delivers robust permission controls and Active Directory interoperability. Learning how to install and configure samba on ubuntu 24.04 provides your local infrastructure with high-performance, authenticated network file shares protected by Linux filesystem permissions.

In this step-by-step tutorial, we demonstrate how to install and configure Samba on Ubuntu 24.04 LTS (Noble Numbat). We cover installing the Samba service daemons, configuring global server parameters in /etc/samba/smb.conf, setting up both private authenticated shares and public guest shares, managing Samba user passwords via smbpasswd, opening firewall ports in UFW, and mounting the network share from Windows and Linux clients.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat). The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A server or virtual machine running Ubuntu 24.04 LTS.
  • A user account configured with administrative sudo privileges.
  • A static local IP address or local DNS resolution on your private LAN subnet.
  • Uncomplicated Firewall (UFW) active to restrict SMB access.

Step 1: Updating System Packages and Installing Samba

Before installing Samba, update your local APT repository index and upgrade installed packages to ensure compatibility with modern kernel networking stacks.

Ubuntu 24.04 provides the latest stable release of Samba directly in its main repository.

Advertisement

Install the samba server daemon and the smbclient testing utility using APT.

Verify that the Samba service daemons (smbd for file sharing and nmbd for NetBIOS name resolution) install cleanly.

# Update APT repository indices and upgrade packages
sudo apt update && sudo apt upgrade -y

# Install Samba and client utilities
sudo apt install -y samba smbclient

# Verify Samba version and service status
samba --version
sudo systemctl status smbd --no-pager

Step 2: Backing Up Default Configuration and Tuning smb.conf

The primary configuration file for Samba is located at /etc/samba/smb.conf. Before introducing custom file share definitions, back up the original vendor configuration file.

Open /etc/samba/smb.conf with administrative privileges.

Advertisement

In the [global] section, specify your local network workgroup name (default is WORKGROUP), configure server string identification, enforce SMB version minimums (such as min protocol = SMB2 to disable legacy vulnerable SMBv1), and define DNS proxy settings.

# Back up original Samba configuration
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

# Inspect active configuration without comments
testparm -s

Step 3: Creating Directory Structure for Private and Public Shares

Establish dedicated shared directories for your network users. In this tutorial, we configure two distinct shares: an authenticated private share for registered users and a read-only public share.

Create the storage directories at /samba/private and /samba/public.

Create a dedicated system group named smbgroup to govern access to the private network share.

Assign ownership and set strict POSIX directory permissions.

# Create directories for network shares
sudo mkdir -p /samba/private /samba/public

# Create a dedicated Samba user group
sudo groupadd smbgroup

# Set ownership and permissions for private share
sudo chown -R root:smbgroup /samba/private
sudo chmod -R 0770 /samba/private

# Set open read/write permissions for public share
sudo chmod -R 0777 /samba/public

Step 4: Creating Samba User Accounts and Setting SMB Passwords

Samba maintains its own encrypted credential database separate from Linux system password hashes in /etc/shadow. However, every Samba user must correspond to an existing system user account.

Create a new system user (or use an existing account) without giving them an interactive login shell.

Add the user to the smbgroup group.

Use the smbpasswd utility with the -a flag to add the user to the Samba database and set their network password.

# Create system user without login shell
sudo useradd -M -s /usr/sbin/nologin sambausr

# Add user to Samba group
sudo usermod -aG smbgroup sambausr

# Set Samba password for the user
sudo smbpasswd -a sambausr

# Enable the Samba user account
sudo smbpasswd -e sambausr

Step 5: Defining Share Configurations in smb.conf

Append your custom share definitions to the end of /etc/samba/smb.conf.

Configure the [Private] share to restrict access strictly to members of @smbgroup with read/write permissions.

Configure the [Public] share to permit guest access without requiring password authentication.

Use the testparm command to validate syntax and verify that no configuration directives are misconfigured.

# Append share definitions to /etc/samba/smb.conf
sudo bash -c 'cat <<EOF >> /etc/samba/smb.conf

[Private]
    comment = Protected Private Directory
    path = /samba/private
    valid users = @smbgroup
    guest ok = no
    writable = yes
    browsable = yes
    create mask = 0770
    directory mask = 0770

[Public]
    comment = Public File Share
    path = /samba/public
    browseable = yes
    read only = yes
    guest ok = yes
EOF'

# Validate configuration file syntax
testparm

Step 6: Configuring Firewall (UFW) to Allow Samba Traffic

Samba requires specific TCP and UDP ports to function across the network. Specifically, port 139 and port 445 (TCP) handle file sharing, while port 137 and port 138 (UDP) handle NetBIOS name resolution and browsing.

Ubuntu's Uncomplicated Firewall (UFW) includes a pre-configured application profile named Samba that encapsulates all necessary ports.

Allow the Samba profile and verify the active rules.

# Allow Samba application traffic through UFW
sudo ufw allow Samba comment 'Allow Samba SMB/CIFS'

# Verify firewall rules
sudo ufw status numbered

Step 7: Starting and Enabling Samba Services

Apply the configuration changes by restarting both the smbd and nmbd systemd services.

Enable the services so that Samba starts automatically whenever the Ubuntu server boots.

Confirm that both services report an active running status.

# Restart Samba services to apply configuration
sudo systemctl restart smbd nmbd

# Enable services on system boot
sudo systemctl enable smbd nmbd

# Verify service status
sudo systemctl status smbd --no-pager

Step 8: Connecting to the Samba Share from Clients

Test connectivity from local and remote client workstations.

From a Linux machine, use smbclient to list available shares: smbclient -L //server_ip -U sambausr, or mount the share via cifs-utils.

From a Windows workstation, open File Explorer, type \\<server_ip_address>\Private into the address bar, and enter your Samba username and password when prompted.

From macOS, open Finder, press Cmd + K, and enter smb://<server_ip_address>/Private.

# Test share access locally via smbclient
smbclient //localhost/Private -U sambausr

# Mounting share permanently on another Linux machine using /etc/fstab
# //server_ip/Private /mnt/samba cifs credentials=/etc/samba/credentials,uid=1000,gid=1000 0 0

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

Windows client reports 'Windows cannot access \\server\Private - Permission Denied'

Resolution: Verify the underlying Linux filesystem permissions. If /samba/private is owned by root:smbgroup with chmod 0770, ensure your Samba user was added to smbgroup using sudo usermod -aG smbgroup username and restart smbd.

Samba service fails to start with 'testparm: Unknown parameter encountered'

Resolution: Run testparm to locate syntax errors in /etc/samba/smb.conf. Ensure all section headers (e.g., [global], [Private]) are spelled correctly without trailing spaces.

Share is visible but cannot write or create files

Resolution: Ensure both the Samba configuration specifies writable = yes and the Linux directory permissions permit write access: sudo chmod -R 775 /samba/private.

Security Best Practices and Hardening

Never bind Samba directly to public internet IP addresses without a VPN tunnel; restrict SMB access strictly to your local subnet in /etc/samba/smb.conf using 'hosts allow = 192.168.1.0/24 127.0.0.1'.

Explicitly enforce 'min protocol = SMB2' in the [global] configuration block to prevent downgrade attacks to insecure legacy SMBv1 protocols.

Assign strong, randomized passwords to all Samba user accounts using smbpasswd.

Keep the Samba package updated promptly to remediate remote code execution and elevation of privilege vulnerabilities.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

3 FAQs
No. Samba relies on the underlying Linux kernel for filesystem permissions. Every authenticated Samba user must correspond to an existing Linux user account in /etc/passwd, though you can disable shell access using /usr/sbin/nologin.
Run sudo smbpasswd username and enter the new password twice when prompted. The changes take effect immediately without needing to restart the Samba service.
Yes. Both macOS Finder and iOS Files app feature native SMB support. In macOS Finder, select Go > Connect to Server and enter smb://server_ip/share_name.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout