Skip to main content

๐Ÿ“‚ Sharing a Folder on Debian Linux via Samba

Last Updated: 2025-06-01
Applies To: Debian 10+, Ubuntu, other Debian-based distributions
Use Case: Share a local folder over the network for access from Windows, macOS, or Linux machines.


๐Ÿงฐ Prerequisites

  • Debian-based Linux system

  • sudo privileges

  • Network connectivity to target devices


๐Ÿ”ง Step 1: Install Samba

Update the system and install Samba:

bash
sudo apt update sudo apt install samba

๐Ÿ“ Step 2: Create a Shared Directory

Choose or create the folder to share. Example:

bash
sudo mkdir -p /srv/share sudo chown nobody:nogroup /srv/share sudo chmod 0775 /srv/share

This creates a public share folder with loose permissions (for anonymous access).


๐Ÿ› ๏ธ Step 3: Configure Samba

Edit the Samba configuration file:

bash
sudo nano /etc/samba/smb.conf

Add the following to the bottom of the file:

ini
[PublicShare] path = /srv/share browseable = yes read only = no guest ok = yes force user = nobody

๐Ÿ“Œ Tip: force user = nobody ensures files are written as the nobody user, preventing permission issues.


๐Ÿ”„ Step 4: Restart Samba Services

bash
sudo systemctl restart smbd

๐Ÿ”ฅ Step 5: Open Firewall (If Enabled)

For systems using ufw (Uncomplicated Firewall):

bash
sudo ufw allow 'Samba'

Or manually:

bash
sudo ufw allow 137,138/udp sudo ufw allow 139,445/tcp

๐Ÿงช Step 6: Access the Share

From a Windows or Linux machine:

  • Open File Explorer or file manager.

  • Go to: \\<your-debian-ip>\PublicShare

You should see the shared folder contents.


๐Ÿ” Optional: Secure with Username/Password

To restrict access:

  1. Disable guest access:

    ini
    guest ok = no
  2. Create a Samba user:

    bash
    sudo smbpasswd -a <your-linux-user>
  3. Restart Samba:

    bash
    sudo systemctl restart smbd

Youโ€™ll now need a username/password to access the share.


๐Ÿงน Troubleshooting

Problem Fix
Can't connect to share Check firewall, Samba config syntax, and network IPs
Files not writable Check folder permissions and force user setting
Authentication issues Ensure Samba user exists and password is set via smbpasswd

  • /etc/samba/smb.conf: Samba main configuration file

  • sudo testparm: Validates Samba config

  • sudo smbstatus: Shows active connections