Normally when you launch the system’s file manager on Linux/Windows system, you will see network shares advised on your network. These shares are only allowed if remote users are connected to the machine.
Samba is a free software that enables one to share files across the network using the SMB(Server Message Block) protocol. This tool was developed by Andrew Tridgell in December 1991 and January 1992.
The cool features associated with Samba are:
- It is easy and quick to deploy
- It offers secured data transfer
- Multichanel technology
- Message signing-with digital signing – users who receive the data packets are assured of the origin point authenticity.
- Allows concurrent operations.(simultaneous access to the files)
- It offers good performance under heavy loads.
- Samba supports POSIX extensions for CIFS/SMB
- Supports NetBIOS over TCP/IP (NBT)
- It supports the NT-style printing service (SPOOLSS)
Samba is supported on various platforms such as Windows and Unix operating systems i.e Solaris, Linux, AIX, and BSD variants.
This guide will equip you with the required knowledge on how to configure Samba Share on Debian.
1 – Install Samba Packages
We will start off by installing Samba on Debian Linux system. This is easy since it is available in the default Debian repositories.
sudo apt update
sudo apt install samba smbclient cifs-utils
Dependency tree:
...
The following NEW packages will be installed:
attr cifs-utils ibverbs-providers keyutils libcephfs2 libgfapi0 libgfrpc0
libgfxdr0 libglusterfs0 libibverbs1 librados2 librdmacm1
python3-cffi-backend python3-cryptography python3-dnspython python3-gpg
python3-markdown python3-pygments python3-requests-toolbelt python3-samba
python3-tdb python3-yaml samba samba-common samba-common-bin
samba-dsdb-modules samba-vfs-modules smbclient tdb-tools
0 upgraded, 29 newly installed, 0 to remove and 0 not upgraded.
Need to get 24.4 MB of archives.
After this operation, 84.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
2 – Set the Samba Global settings
The Samba configuration file is located under /etc/samba/smb.conf. In this file, there are several changes we need to make. Although Debian is intelligent enough to provide default configurations, it is also good to verify this.
Open the file using a preferred editor.
sudo vim /etc/samba/smb.conf
In the file, make make adjustments as you deem fit, example for workgroup.
workgroup = WORKGROUP
3 – Create Shared Samba Directory
Here, you can share both public and private directories. So we will create the two directories as below.
sudo mkdir /public
sudo mkdir /private
Now edit the Samba conf and add the two directories.
sudo vim /etc/samba/smb.conf
At the end of the file, add the shares and authentication methods to access it.
[public]
comment = Public Folder
path = /public
writable = yes
guest ok = yes
guest only = yes
force create mode = 775
force directory mode = 775
[private]
comment = Private Folder
path = /private
writable = yes
guest ok = no
valid users = @smbshare
force create mode = 770
force directory mode = 770
inherit permissions = yes
4 – Create Samba User and Group
We need the Samba share user group to access the Private share as specified in the conf above. So we will create the group as below.
sudo groupadd smbshare
Add the necessary permissions for the private share.
sudo chgrp -R smbshare /private/
sudo chgrp -R smbshare /public
Set the right directory permissions.
sudo chmod 2770 /private/
sudo chmod 2775 /public
In the above command, the value 2 at the beginning, stands for the SGID bit. This allows newly created files to inherit the parent group.
Next, create a no login local user to access the private share.
sudo useradd -M -s /sbin/nologin sambauser
Add the user to the Samba share group created above.
sudo usermod -aG smbshare sambauser
Now create an SMB password for the user.
sudo smbpasswd -a sambauser
Enable the created account:
sudo smbpasswd -e sambauser
5 – Verify the Samba configuration
Once changes have been made to the config file, it is recommended that you test it using the below command:
sudo testparm
Execution output:
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Weak crypto is allowed
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
# Global parameters
[global]
interfaces = 192.168.205.0/24 eth0
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
.....
[public]
comment = Public Folder
force create mode = 0775
force directory mode = 0775
guest ok = Yes
guest only = Yes
path = /public
read only = No
[private]
comment = Private Folder
force create mode = 0770
force directory mode = 0770
inherit permissions = Yes
path = /private
read only = No
valid users = @smbshare
The above output shows that everything is configured appropriately. Now proceed as below.
Create demo files in the Samba shares:
sudo mkdir /private/demo-private /public/demo-public
sudo touch /private/demo1.txt /public/demo2.txt
Restart the Samba service for the changes to apply.
sudo systemctl restart nmbd
If you have a firewall running, you need to allow remote access from the specified IP range:
sudo ufw allow from 192.168.205.0/24 to any app Samba
6 – Access Shares from the Client
This guide demonstrates how to access the Share files using both Windows and Linux systems.
First, try accessing the share from your local machine.
$ smbclient '\\localhost\private' -U sambauser
Enter WORKGROUP\sambauser's password:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Tue Feb 8 01:31:42 2022
.. D 0 Tue Feb 8 01:25:51 2022
demo1.txt N 0 Tue Feb 8 01:31:42 2022
demo-private D 0 Tue Feb 8 01:31:32 2022
39987708 blocks of size 1024. 32647972 blocks available
smb: \> exit
Now proceed as set up clients.
1. Setup a Windows Client
To access the share from Windows, browse using the IP address of the Samba share system as below.
Open a run box using Win+R and proceed as shown.

The shared folders should appear as below.

Open one of the folders and create a file.

The file should be visible on the Samba server machine.

Now mount the Samba share permanently on your Windows system. Click on This PC->Map Network Drive

Provide the Path details as below.

Enter the Samba user credentials.

You will have the share available as shown.

2. Setup a Linux client
To set up a Linux client, you will need Samba packages:
sudo apt install samba-client cifs-utils
Once installed, navigate to File manager->Other locations and add your share using the syntax below.
smb://servername/Share_name
For example:

Enter the credentials for the samba user.

That is it! You have your Samba share as below.

Voila!
I hope you enjoyed this guide on how to configure Samba Share on Debian Linux system. Now you can easily share files over a network between Windows and Linux systems.
See more:
This was super helpful but I’m running into a problem when trying to create or edit files from the windows file explorer. I followed your guide up to that point and had no problems, but when I try to log in to the /private folder from windows I get:
“\\192.168.1.5\private is not accessible. You might not have permission to use this network resource.”
I can map the network location and open files inside, but any time I try to edit them or create a new file I get permissions errors.
Here’s my permissions settings for my shared folders:
drwxrwsr-x 2 root smbshare 4096 May 19 09:20 public
drwxrws— 2 root smbshare 4096 May 19 08:45 private
Ok I think it’s working now. I had to run these commands:
sudo chown -R my_username /public
chmod -R a+w /public
sudo systemctl restart nmbd
Now when I map the network drive in windows (\\192.168.1.5\public) I have write privileges.
Starting here:
Now edit the Samba conf and add the two directories.
sudo vim /etc/samba/smb.conf
At the end of the file, add the shares and authentication methods to access it.
I have no idea as to what directory or where in the directory tree to put these /public and /private directories.
The instructions on the linux side worked flawlessly for me on Raspberry Pi OS:
# lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
I have an old embroidery machine that mounts as a DOS disk via USB and that’s the only way to transfer files to the machine for sewing / embroidery. Using a Raspberry Pi and a wifi dongle, I was able to create a samba share using these instructions and then mount that share on my remote MacOS MacBook Pro. I can now create the files on the MacBook and transmit them over to the rPi using samba. I could not get the DOS disk to directly work as the share, so there is still an intermediary step of having to copy them from the rPi storage to the mounted embroidery machine, but that is really easy-peasy compared to having to bring the laptop over to the machine, plug it in via USB, etc. Thank you!
Happy to hear such good feedback on working installations. Thanks!
This is a really great guide, thanks so much for posting it!
Thank you.