Samba Servers

Samba implements the SMB (Server Message Block) protocol on Ubuntu, allowing Windows clients to access files and printers on Linux servers as if they were Windows shares. It is the standard way to share files between Ubuntu and Windows systems in mixed environments. Samba can also act as an Active Directory domain controller, though this article focuses on the more common file server use case.

What is Samba?

Samba file server:

  Ubuntu Server (192.168.1.50):
    Samba service (smbd, nmbd)
    Exports: \SERVER\shared, \SERVER\home

  Windows Client:
    \192.168.1.50\shared  → maps to /srv/samba/shared on Ubuntu
    Authenticates with Samba user account

  Compared to NFS:
    NFS: fast, Linux-to-Linux, no Windows support
    SMB: Windows-compatible, cross-platform, more overhead

Setting up a file share

sudo apt update
sudo apt install -y samba

# Create shared directory:
sudo mkdir -p /srv/samba/shared
sudo chown nobody:nogroup /srv/samba/shared
sudo chmod 1777 /srv/samba/shared    # Sticky bit: users can only delete own files

# Configure Samba:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
sudo nano /etc/samba/smb.conf

/etc/samba/smb.conf — key sections

[global]
    workgroup = EXAMPLE
    server string = Ubuntu File Server
    security = user
    map to guest = Bad User    # Unauthenticated = guest
    log file = /var/log/samba/log.%m
    max log size = 1000

[shared]
    comment = Shared Files
    path = /srv/samba/shared
    browseable = yes
    writable = yes
    guest ok = no              # Require authentication
    valid users = @samba-users # Only users in samba-users group

[homes]
    comment = Home Directories
    browseable = no
    valid users = %S
    writable = yes
# Validate config:
testparm

# Restart Samba:
sudo systemctl restart smbd nmbd
sudo systemctl enable smbd nmbd

# Open firewall:
sudo ufw allow 'Samba'

Samba user management

# Create Linux user and add to samba-users group:
sudo groupadd samba-users
sudo useradd -M -G samba-users -s /sbin/nologin irfan    # No shell needed
sudo smbpasswd -a irfan    # Set Samba password (separate from Linux password)
sudo smbpasswd -e irfan    # Enable the account

# List Samba users:
sudo pdbedit -L

# Change Samba password:
sudo smbpasswd irfan

# Disable a Samba user:
sudo smbpasswd -d irfan

Accessing from Windows

# From Windows:
# Open File Explorer → \192.168.1.50\shared
# Or map a network drive: net use Z: \192.168.1.50\shared /user:irfan

# From Ubuntu (access a Windows or Samba share):
sudo apt install -y smbclient
smbclient //192.168.1.50/shared -U irfan

# Mount Samba share permanently on Ubuntu:
sudo apt install -y cifs-utils
sudo nano /etc/fstab

/etc/fstab CIFS entry

//192.168.1.50/shared  /mnt/samba  cifs  credentials=/etc/samba/credentials,uid=1000,gid=1000,iocharset=utf8,_netdev  0  0
# Create credentials file (don't put passwords in /etc/fstab directly):
sudo nano /etc/samba/credentials
# username=irfan
# password=yourpassword
sudo chmod 600 /etc/samba/credentials
sudo mount -a

Conclusion

Never put Samba credentials directly in /etc/fstab — use a credentials file with mode 600 so only root can read it. Use testparm to validate smb.conf before restarting Samba; a syntax error in smb.conf causes Samba to fail silently on restart and leaves the old configuration running (or no configuration at all). Set guest ok = no on any share with sensitive data to require authentication.

FAQ

Is Samba Servers important for Ubuntu administrators?+

Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.

Should I practice this on a live server?+

Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.

What should I do after reading this article?+

Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.

Need help with Ubuntu administration?

Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.

Hire Me for Support