Thursday, December 26, 2024
Google search engine
HomeGuest BlogsHow To Configure Samba Share on Debian 11 / Debian 10

How To Configure Samba Share on Debian 11 / Debian 10

.tdi_3.td-a-rec{text-align:center}.tdi_3 .td-element-style{z-index:-1}.tdi_3.td-a-rec-img{text-align:left}.tdi_3.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_3.td-a-rec-img{text-align:center}}

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:

.tdi_2.td-a-rec{text-align:center}.tdi_2 .td-element-style{z-index:-1}.tdi_2.td-a-rec-img{text-align:left}.tdi_2.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_2.td-a-rec-img{text-align:center}}

  • 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 11 / Debian 10.

Step 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 install samba smbclient cifs-utils

Dependency tree:

The following additional packages will be installed:
  attr 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-common samba-common-bin samba-dsdb-modules
  samba-vfs-modules tdb-tools
Suggested packages:
  winbind python-cryptography-doc python3-cryptography-vectors python3-sniffio
  python3-trio python-markdown-doc python-pygments-doc ttf-bitstream-vera
  bind9 bind9utils ctdb ldb-tools ntp | chrony smbldap-tools ufw
  heimdal-clients
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

Step 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

Step 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

Step 4 – Create Samba Share 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

Step 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

Step 6 – Access the 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.

How To Configure Samba Share on Debian 11 Debian 10 1

The shared folders should appear as below.

How To Configure Samba Share on Debian 11 Debian 10 1 1

Open one of the folders and create a file.

How To Configure Samba Share on Debian 11 Debian 10 6

The file should be visible on the Samba server machine.

How To Configure Samba Share on Debian 11 Debian 10 7 1

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

How To Configure Samba Share on Debian 11 Debian 10 2

Provide the Path details as below.

How To Configure Samba Share on Debian 11 Debian 10 3

Enter the Samba user credentials.

How To Configure Samba Share on Debian 11 Debian 10 4

You will have the share available as shown.

How To Configure Samba Share on Debian 11 Debian 10 5

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:

How To Configure Samba Share on Debian 11 Debian 10 8

Enter the credentials for the samba user.

How To Configure Samba Share on Debian 11 Debian 10 9

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

How To Configure Samba Share on Debian 11 Debian 10 10

Voila!

I hope you enjoyed this guide on how to configure Samba Share on Debian 11 / Debian 10. Now you can easily share files over a network between Windows and Linux systems.

See more:

.tdi_4.td-a-rec{text-align:center}.tdi_4 .td-element-style{z-index:-1}.tdi_4.td-a-rec-img{text-align:left}.tdi_4.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_4.td-a-rec-img{text-align:center}}

RELATED ARTICLES

Most Popular

Recent Comments