How to Install and Configure Samba on Debian Server

 

Hello Friend,
Let's start by defining what is Samba? according to wikipedia Samba is a free software re-implementation of the SMB networking protocol, and was originally developed by Andrew Tridgell. Samba provides file and print services for various Microsoft Windows clients and can integrate with a Microsoft Windows Server domain, either as a Domain Controller (DC) or as a domain member. As of version 4, it supports Active Directory and Microsoft Windows NT domains.
Let's make it simple, samba is used to communicate with windows file shares and printer services, it's allow windows and linux machines to access files from our server too.

Here I'll just guide you to how to make a folder on your home directory and share it across the network from your server.

  • Installing Samba

first we need to install samba on the server by typing the following command

$ sudo apt install samba

second we need to make sure that samba is active and enabled on the system startup by typing the following command

$ sudo systemctl status smbd

You should get that samba is enabled and active, but for some reason you got a different result, just type the following commands

$ sudo systemctl enable smbd
$ sudo systemctl start smbd
$ sudo systemctl enable nmbd
$ sudo systemctl start nmbd

  •  Add/Remove user to Samba

First be noted that the user we will add to samba must be a user on the server, if you add a random user that can't be found on the server you will get and error message "Failed to add entry for user <username>"

Second to add a user to samba, just type

$ sudo smbpasswd -a <username>
Example
$ sudo smbpasswd -a codivya

You will be asked to enter a new password and repeat the password, then you will got a message telling you that the user is added successfully.

To remove a user from samba, just type

$ sudo smbpasswd -x <username>
Example
$ sudo smbpasswd -x codivya

  • Configure Samba

The configuration file can be found in /etc/samba/smb.conf, here you can configure everything, but here in this tutorial we will just configure the folder that we will create and make it accessible, first create a folder in the user's home directory that you just added by typing

$ mkdir SMBData

let's get back to configuration file, just open it by typing

$ sudo vim /etc/samba/smb.conf

go to the bottom of the file and add the following and of course replace "codivya" with the username that you just added to samba

[SMBData]
    comment = Main Data Share
    path = /home/codivya/SMBData
    browseable = yes
    writeable = yes
    read only = no
    valid users = codivya

Save the file and exit, now restart samba by typing

$ sudo systemctl restart smbd
$ sudo systemctl restart nmbd

If everything works, you should now can access SMBData folder from any device on your network with the username and password you just created previously.

-----------------------------------------------

This was a quick and simple tutorial, thanks for reading.


Comments