Skip to content

Linux Samba Share Connection Error Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Linux Samba Share Connection Error Fix. We cover key concepts, practical examples, and best practices.

Samba share connections fail with errors like "mount error(13): Permission denied", "NT_STATUS_ACCESS_DENIED", or "network name cannot be found". These occur when Samba user credentials are wrong, the share path does not exist, firewall blocks NetBIOS/SMB ports, or SELinux/AppArmor interferes.

The Problem

smbclient //server/share -U user

Error:

session setup failed: NT_STATUS_LOGON_FAILURE

Or:

sudo mount -t cifs //server/share /mnt -o username=user

Error:

mount error(13): Permission denied

Wrong Approach

# WRONG — using the system user password directly
smbclient //server/share -U root

# WRONG — no domain specified for domain-authenticated servers
mount -t cifs //server/share /mnt -o username=user%password

Right Approach

# Add the user to Samba first
sudo smbpasswd -a user

# Then connect with the Samba password
smbclient //server/share -U user -W WORKGROUP

Expected output:

Try "help" to get a list of possible commands.
smb: \>

Step-by-Step Fix

Step 1: Check the Samba configuration

sudo testparm

Step 2: Verify the share exists

smbclient -L //localhost -U%

Step 3: Fix the Samba configuration

[share]
   path = /srv/samba/share
   valid users = user
   read only = no
   browsable = yes

Step 4: Add Samba user

sudo smbpasswd -a user
sudo systemctl restart smbd

Step 5: Fix SELinux context for Samba

sudo semanage fcontext -a -t samba_share_t "/srv/samba(/.*)?"
sudo restorecon -Rv /srv/samba

Step 6: Check firewall

sudo firewall-cmd --add-service=samba --permanent
sudo firewall-cmd --reload

Step 7: Mount the share

sudo mount -t cifs //server/share /mnt -o username=user,uid=$(id -u),gid=$(id -g)

Prevention Tips

  • Create a separate Samba password with smbpasswd, not system password
  • Set SELinux context to samba_share_t for all Samba directories
  • Open Samba ports in the firewall: 137-139 (NetBIOS), 445 (SMB)
  • Use valid users to restrict share access to specific users
  • Test with smbclient before setting up permanent mounts

Common Mistakes with samba config

  1. Using foldl instead of foldl' causing stack overflow on large lists
  2. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  3. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable

These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between Samba user and system user?

A system user exists in /etc/passwd for Linux login. A Samba user is registered with smbpasswd for SMB authentication. They must be the same username, but the passwords are separate. Run sudo smbpasswd -a username to set the Samba password.

Why can I connect via smbclient but not mount the share?

This usually means the mount command has wrong options or the cifs kernel module is missing. Install cifs-utils, check the module with lsmod | grep cifs, and use the correct uid/gid options: -o username=user,uid=1000,gid=1000.

How do I make Samba shares accessible by guest users?

Add map to guest = Bad User and guest ok = yes to the share definition in smb.conf. Set security = user and ensure the share path has world-readable permissions. Be aware that guest access skips authentication.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro