Install Samba File Sharing on Debian 12

This tutorial intends to teach you to Install and Configure Samba File Sharing on Debian 12 Booworm. Also, you will learn to Set up Samba Clients on both Windows and Linux.

Samba is a powerful tool that allows you to create seamless file and printer sharing to SMB/CIFS clients from a Linux server/desktop.

Debian 12 ships with the Samba version 4.17.

Install and Configure Samba File Sharing on Debian 12 Booworm

To set up a Samba server on Debian 12, you must have access to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow this guide on Initial Server Setup with Debian 12 Bookworm.

Now proceed to the following steps to start your Samba server installation and configuration.

Step 1 – How To Install Samba with APT on Debian 12?

The smbclient is a tool that allows you to access Samba from the command line. You can install this package by using your APT on Debian 12.

First, run the system update with the following command:

sudo apt update

Then, use the following command to install your Samba packages:

sudo apt install samba smbclient cifs-utils

This will install all the dependencies and required packages for Samba.

Verify your installation by checking its version:

samba --version
Version 4.17.9-Debian

Step 2 – How To Configure Samba Share on Debian 12?

At this point, you need to make some changes to the Samba config file and create share Samba directories. 

Where is the Samba file on Debian?

The Samba configuration file can be found at the /etc/samba/smb.conf directory. 

Set Samba Global Settings

At this point, you need to open the Samba configuration file with your favorite text editor, here we use vi editor:

sudo vi /etc/samba/smb.conf

Under the Global section, find the line below and make sure it is like this:

workgroup = WORKGROUP

When you are done, save and close the file.

Create Shared Samba Directory

At this point, you can share both public and private directories. So you can create the two directories by using the following commands:

# sudo mkdir /public 
# sudo mkdir /private

Now you need to open the Samba config file again and add the shares and authentication methods to the end of the file.

sudo vi /etc/samba/smb.conf
   comment = Public Folder
   path = /public
   writable = yes
   guest ok = yes
   guest only = yes
   force create mode = 775
   force directory mode = 775
   comment = Private Folder
   path = /private
   writable = yes
   guest ok = no
   valid users = @smbshare
   force create mode = 770
   force directory mode = 770
   inherit permissions = yes

When you are done, save and close the file.

Create a Samba Share User Group

At this point, you need the Samba share user group to access the Private share as specified in the config file above. 

Create the group by using the command below:

sudo groupadd smbshare

Set the correct permissions for the private and public share by using the commands below:

# sudo chgrp -R smbshare /private/
# sudo chgrp -R smbshare /public

Next, set the correct permissions for the directories:

# sudo chmod 2770 /private/ 
# sudo chmod 2775 /public

Note: The value 2 at the beginning of the above commands, stands for the SGID bit. This allows newly created files to inherit the parent group.

Now you should create a no-login local user to access the private share by using the command below:

sudo useradd -M -s /sbin/nologin sambauser

Then, add the user to the Samba share group on Debian 12 with the following command:

sudo usermod -aG smbshare sambauser

Finally, set a password for your Samba user:

sudo smbpasswd -a sambauser
New SMB password:
Retype new SMB password:
Added user sambauser.

Enable the created account by using the following command:

sudo smbpasswd -e sambauser
Enabled user sambauser.

Verify Samba Configuration

When you are done with the above steps, you can test your Samba configuration on Debian 12 that is working correctly or not with the following command:

sudo testparm
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Weak crypto is allowed by GnuTLS (e.g. NTLM as a compatibility fallback)


Press enter to see a dump of your service definitions

# Global parameters
        log file = /var/log/samba/log.%m
        logging = file
        map to guest = Bad User
        max log size = 1000
        obey pam restrictions = Yes
        pam password change = Yes
        panic action = /usr/share/samba/panic-action %d
        passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
        passwd program = /usr/bin/passwd %u
        server role = standalone server
        unix password sync = Yes
        usershare allow guests = Yes
        idmap config * : backend = tdb

        browseable = No
        comment = Home Directories
        create mask = 0700
        directory mask = 0700
        valid users = %S

        browseable = No
        comment = All Printers
        create mask = 0700
        path = /var/tmp
        printable = Yes

        comment = Printer Drivers
        path = /var/lib/samba/printers

        comment = Public Folder
        force create mode = 0775
        force directory mode = 0775
        guest ok = Yes
        guest only = Yes
        path = /public
        read only = No

        comment = Private Folder
        force create mode = 0770
        force directory mode = 0770
        inherit permissions = Yes
        path = /private
        read only = No
        valid users = @smbshare

This means that everything is configured appropriately. 

Create Demo Files in Samba Share

At this point, you can create demo files in the Samba shares. To do this. you can run the following commands:

# sudo mkdir /private/demo-private /public/demo-public
# sudo touch /private/demo1.txt /public/demo2.txt

How To Restart Samba Service?

To apply the changes, restart the Samba service on Debian 12:

sudo systemctl restart nmbd

Configure Firewall for Samba

If you have a firewall running, you need to allow remote access from the specified IP range as shown below:

sudo ufw allow from to any app Samba

Access Share Files From Local Machine

Before you set up Samba clients, you can try accessing your share files with the command below on Debian 12:

smbclient '\\localhost\private' -U sambauser
Password for [WORKGROUP\sambauser]:
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Thu Jul 13 05:09:10 2023
  ..                                  D        0  Thu Jul 13 05:03:52 2023
  demo1.txt                           N        0  Thu Jul 13 05:09:10 2023
  demo-private                        D        0  Thu Jul 13 05:08:59 2023

                50971500 blocks of size 1024. 45052604 blocks available
smb: \>

Step 3 – Set up Samba Share Windows Client

At this point, we want to show you access to the share from Windows. First, open a run box using Win+R and enter your Debian 12 IP address in the box and click Ok:

Run Box, open Samba share
Run Box

Then, the Samba shared folders on Debian 12 should appear as below:

Samba Shared Folders
Shared Folders

You can open one of the files, and create a new file there. You should see the file on your server machine too.

Mount Samba Share Permanently

At this point, you can mount the Samba share permanently on your Windows system. Click on This PC->Map Network Drive. This will open a window for you, provide the Path details and click Finish.

Map Samba Network Folder
Map Samba Network Folder

Then, enter the Samba user credentials and click ok.

You will have the share available on your This PC.

Step 4 – Set up Samba Linux Client

At this point, you can access the share folders from a Linux client. To do this, you need to have Samba packages installed on your server. Here our Linux client is Debian 12:

sudo apt install samba-client cifs-utils

Then, navigate to File Manager ->Other locations and add your share using the syntax below.


Enter the credentials for the Samba user. That is it! You have your Samba share on your Linux client machine.

For more information, you can visit the Samba Documentation page.


At this point, you have learned to Install and Configure Samba Sharing File on Debian 12 Bookworm. And also, you have learned to set up Samba clients on both Windows and Linux machines. Hope you enjoy it. You may be interested in these articles:

How To Install AnyDesk on Debian 12 Bookworm

Stress Test and Benchmark CPU Performance Debian

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!