How to Install and Setup Samba Server on Debian 12?


Samba is an open-source software that shares files, printers, and other network resources over a network. Samba can also act as a domain controller, a file server, or a print server across different operating systems Linux and Windows systems. Based on its importance, this tutorial will explain how to install as well as configure the Samba server on Debian 12. In addition, create a shared folder and a user account for accessing it from Windows as well as Linux.

The supported outline is given below:

Let’s begin with the installation.

How to Install and Setup Samba Server on Debian 12?

Samba works as a server or a client, based on the setting/configuration. Installing and setting up Samba on Debian 12 is a simple process that can be done in a few steps.

Step 1: Update System Packages

To install as well as configure the Samba server, users need to update packages via the below commands:

sudo apt update

Step 2: Install Samba

Then, install the samba package using the “apt” package manager. It installs the Samba server as well as its dependent packages:

sudo apt install samba

Step 3: Check Samba Services

You can check the status of the Samba service with the following command:

sudo systemctl status smbd

Alternatively, users can verify the installed version via the “version” utility:

smbstatus --version

Step 4: Edit the Samba Configuration File

Now, focus on creating a simple shared folder that can be accessed by anyone on the network. To do that, scroll down to the end of the “/etc/samba/smb.conf” configuration file and add the following lines:

sudo nano /etc/samba/smb.conf

The file contains many options and comments that explain their usage. Users can edit the file based on its requirements:

[share]
path = /home/sambauser/share
valid users = sambauser
read only = no
browseable = yes

The above configuration creates a “share” named shared that points to the directory “/home/sambauser/share” on the server. The “valid users” allow only the new user “sambauser” (created later in the below steps). The “read only” option allows write access to the specified folder. The “browseable” option allows the share to be visible on the network:

Save and close the file by pressing Ctrl+O followed by Ctrl+X.

Optional: Users can also add a “guest ok” option to allow anonymous access to the share. Also, use the static IP address configured on the Samba server.

Step 5: Restart Samba Service

To apply the changes, users need to restart the Samba services via the “systemctl” command with the “smbd” (service name)

sudo systemctl restart smbd

Step 6: Create a User Account

Now, create a new user account on the server via the “adduser” command. It is utilized for accessing the shared folder. For instance, creating a user named “sambauser” must be the same in the above configuration file (in Step 4):

sudo adduser sambauser

Step 7: Set Password for “sambauser” Account

Now, users must set a strong password for the “sambauser” account using the “smbpasswd” command:

sudo smbpasswd -a sambauser

Step 8: Create a Directory on the Server

In this step, create a directory that will be shared with the Windows/Linux clients. Let’s create a directory named “share” in the “/home/sambauser” folder, using the “mkdir” command:

sudo mkdir /home/sambauser/share

Step 9: Change Ownership and Permissions

Users need to change the ownership as well as permissions of the “share” directory so that only the “sambauser” can read and write to it:

sudo chown sambauser:sambauser /home/sambauser/share
sudo chmod 700 /home/sambauser/share

Verify Configuration File

To check the Samba (configuration file) has successfully loaded services, execute the “testparm” command:

testparm

If users find any issues, restart the Samba service on Debian 12 by following Step 5.

Install “samba-client” Package (Make a Local Connection)

To test the local connection, install the “samba-client” package with the dependencies such as “cifs-utils”:

sudo apt install samba-client cifs-utils

Verify Local Connection

To verify the samba configuration, use the “smbclient” command with the “\\localhost\share” by specifying the “sambauser” (username). Users can explore more options via the “help” utility as below:

smbclient '\\localhost\share' -U sambauser

Now, you have successfully installed and configured the Samba server on Debian 12.

Access a Shared Folder From Windows to Linux

Let’s test the Samba configuration by accessing the shared folder from a Windows client:

Map Network Drive (In Windows)

To access the shared folder from Windows, hit the “Network” Drive from File Explorer. Then, pick the “Map network drive” option by pressing the right-click on it. It pops up an interface to map “Drive” and “Folder”.

Here, “Z” is selected as a “Drive” and the “Folder” is “\\192.168.157.135\share” where “192.168.157.135” is the IP address of the Debian server:

Alternatively, type “\\server_ip\share” in the address bar of File Explorer.

Enter Username and Password

It prompts and asks for a username as well as a password. Enter “sambauser” as the username and the password you set in steps 6 and 7. Finally, end up with the “OK” button:

Accessed Shared Folder

Finally, users access the “share” folder on the Debian server from your Windows client. Now, create/delete/modify files as well as folders as they wish. Let’s create a folder “Linuxgenie” and access from Debian 12:

Access a Shared Folder From Linux to Windows

Now, go to the Linux terminal and specify the path such as “/home/sambauser/share” to access the newly created “Linuxgenie” folder (in the above section):

sudo ls /home/sambauser/share

In this way, you have successfully installed and configured the Samba server on Debian 12.

Access a Shared Folder From Linux to Linux

To access the shared folder from one linux machine (Ubuntu) to another (Debian 12), select the “Other Locations” options and type “smb://servername/Share_name” on the “Connect to Server” address bar. Finally, hit the “Connect” button.

Here, the server name/IP address is “192.168.157.135” and the folder is “share”:

It displays a prompt asking for the username as well as a password. Enter “sambauser” as the username and the password you set in Step 3. Finally, hit the “Connect” button:

Note: Make sure, the user selects the “Registered User” that is “sambauser” (created user in the Debian system).

Verification

Now, users can verify that the “Linuxgenie” shared folder is accessed by the Ubuntu system:

That is all from accessed shared folders from Windows to Linux as well as Linux to Linux.

Conclusion

Samba is a free and open-source software that permits Linux as well as Windows systems to share files on a network. To install and setup Samba Server on Debian 12, update your system and install Samba packages. Then, configure the main Samba configuration file (/etc/samba/smb.conf). Now, create a shared folder and set the permissions. After that, create a Samba user and assign a password. Finally, restart the Samba service and enable it to start on boot. So, test the connection from Windows or Linux and access the shared folder.

This tutorial has explained how to install as well as configure a Samba server on Debian 12.

Print Friendly, PDF & Email
Categories