How to implement a complete Samba Server in Ubuntu 24.04?

Samba Server on Ubuntu 24.04: Installation and initial configuration

Samba Server on Ubuntu 24.04: Installation and initial configuration

Last week, we shared a first updated guide, focused on offering them the theory and practice, essential or basic so that anyone can achieve, quickly, directly and easily, the implement a simple Samba Server in Ubuntu 24.04. Something that can be really useful to carry out, both within a small home and a small office. Above all, why in it, we only address the use of one or more public folders (without access users/passwords), on a partition or folder of the operating system's own hard drive, such as from an additional hard drive automatically mounted via fstab.

But, given that when it is required to implement something more robust and efficient, in order to offer an efficient and safe storage and sharing of files within a network and administrative structure, the ideal thing is to create folders for different types or groups of users, since today we will explain in this second part how we can achieve this objective. That is, the "how you can implement a complete Samba Server in Ubuntu 24.04" with folders protected by username and password.

Samba Server on Ubuntu 24.04: Installation and initial configuration

But, before starting this new and second quick guide on implementing «a very complete Samba Server on Ubuntu 24.04, we recommend you explore the previous related post with this topic, at the end of reading it:

Samba Server on Ubuntu 24.04: Installation and initial configuration
Related article:
How to implement a simple Samba Server in Ubuntu 24.04?
Samba is the standard set of Windows interoperability programs for Linux and Unix.

Samba is a multifunctional server product, which also provides an implementation of the file server, print service, and identity server (winbind).

A complete Samba Server on Ubuntu 24.04: Final configuration

Steps to build a complete Samba Server on Ubuntu

Continuing with the working scenario of the first quick guide on Samba, we will pretend that we are in a Work network of a school institution, so that in addition to a public folder accessible to all workers and students, shared folders can be offered for all those work groups that are necessary. Such as the staff: Manager, Teacher, Administrative and Worker.

Step 1: Start and check the previously created Samba Server

A complete Samba Server on Ubuntu 24.04 - Screenshot 01

A complete Samba Server on Ubuntu 24.04 - Screenshot 02

Step 2: Management of virtual users within the Operating System and Samba

Keep in mind that the users to be created due to good computing practice will be through the "useradd" command and the "nologin" parameter, with the objective that they have restricted access to the server, that is, they cannot actually make a physical login into the server with said user account.

Or in other words, this way of creating users allows us to create accounts that do not require interactive login capabilities within the manipulated server or host. Therefore, its ideal purpose is prevent users from logging in, but still have a valid Shell to execute actions.

Command orders used

Creation of users within the operating system

useradd -M -s /sbin/nologin usersdir #Dirección general
useradd -M -s /sbin/nologin usersaca #Subdirección Academica
useradd -M -s /sbin/nologin usersadm #Subdirección Administrativa
useradd -M -s /sbin/nologin userstec #Subdirección Técnica
useradd -M -s /sbin/nologin usersdoc #Docentes
useradd -M -s /sbin/nologin usersobr #Obreros

A complete Samba Server on Ubuntu 24.04 - Screenshot 03

Password creation for each previous user

passwd usersdir
passwd usersaca
passwd usersadm
passwd userstec
passwd usersdoc
passwd usersobr

A complete Samba Server on Ubuntu 24.04 - Screenshot 04

Process of adding (associating) users to the Samba Server using a password

smbpasswd -a usersdir
smbpasswd -a usersaca
smbpasswd -a usersadm
smbpasswd -a userstec
smbpasswd -a usersdoc
smbpasswd -a usersobr

A complete Samba Server on Ubuntu 24.04 - Screenshot 05

User group creation process

groupadd dirgen
groupadd sdiraca
groupadd sdiradm
groupadd sdirtec
groupadd obreros
groupadd docentes

A complete Samba Server on Ubuntu 24.04 - Screenshot 06

Process of adding (associating) user groups and valid users

usermod -aG dirgen usersdir
usermod -aG sdiraca usersaca
usermod -aG sdiradm usersadm
usermod -aG sdirtec userstec
usermod -aG obreros usersobr
usermod -aG docentes usersdoc

A complete Samba Server on Ubuntu 24.04 - Screenshot 07

Process of creating folders (directories) for user groups

sudo mkdir /media/disk2/dirgen/ ; sudo chmod -R 777 /media/disk2/dirgen/ ; sudo chown nobody:nogroup -R /media/disk2/dirgen/
sudo mkdir /media/disk2/dirgen/sdiraca ; sudo chmod -R 777 /media/disk2/dirgen/sdiraca ; sudo chown nobody:nogroup -R /media/disk2/dirgen/sdiraca
sudo mkdir /media/disk2/dirgen/sdiradm ; sudo chmod -R 777 /media/disk2/dirgen/sdiradm ; sudo chown nobody:nogroup -R /media/disk2/dirgen/sdiradm
sudo mkdir /media/disk2/dirgen/sdirtec ; sudo chmod -R 777 /media/disk2/dirgen/sdirtec ; sudo chown nobody:nogroup -R /media/disk2/dirgen/sdirtec
sudo mkdir /media/disk2/dirgen/obreros ; sudo chmod -R 777 /media/disk2/dirgen/obreros ; sudo chown nobody:nogroup -R /media/disk2/dirgen/obreros
sudo mkdir /media/disk2/dirgen/docentes ; sudo chmod -R 777 /media/disk2/dirgen/docentes ; sudo chown nobody:nogroup -R /media/disk2/dirgen/docentes

A complete Samba Server on Ubuntu 24.04 - Screenshot 08

Step 3: Managing the Samba configuration file and new shares

At this point, we must open our "smb.conf" file, previously backed up, to then insert the following content, and continue the process:

[DirGen]
   comment = Carpeta compartida DirGen
   path = /media/disk2/dirgen
   valid users = root @usersdir
   write list = root @usersdir
   browsable = yes
   writable = yes
   guest ok = no
   force create mode = 0770
   force directory mode = 0770
   read only = no
   force group = dirgen

[SubDirAca]
   comment = Carpeta compartida Sub Dir Academica
   path = /media/disk2/dirgen/sdiraca
   valid users = root @usersaca
   write list = root @usersaca
   browsable = yes
   writable = yes
   guest ok = no
   force create mode = 0770
   force directory mode = 0770
   read only = no
   force group = sdiraca

[SubDirAdm]
   comment = Carpeta compartida Sub Dir Administrativa
   path = /media/disk2/dirgen/sdiradm
   valid users = root @usersadm
   write list = root @usersadm
   browsable = yes
   writable = yes
   guest ok = no
   force create mode = 0770
   force directory mode = 0770
   read only = no
   force group = sdiradm

[SubDirTec]
   comment = Carpeta compartida Sub Dir Tecnica
   path = /media/disk2/dirgen/sdirtec
   valid users = root @userstec
   write list = root @userstec
   browsable = yes
   writable = yes
   guest ok = no
   force create mode = 0770
   force directory mode = 0770
   read only = no
   force group = sdirtec

[Obreros]
    comment = Carpeta compartida Trabajadores Obreros
    path = /media/disk2/dirgen/obreros
    valid users = root @usersobr
    write list = root @usersobr
    browsable = yes
    writable = yes
    guest ok = no
    force create mode = 0770
    force directory mode = 0770
    read only = no
    force group = obreros

[Docentes]
    comment = Carpeta compartida Trabajadores Docentes
    path = /media/disk2/dirgen/docentes
    valid users = root @usersdoc
    write list = root @usersdoc
    browsable = yes
    writable = yes
    guest ok = no
    force create mode = 0770
    force directory mode = 0770
    read only = no
    force group = docentes

A complete Samba Server on Ubuntu 24.04 - Screenshot 09

A complete Samba Server on Ubuntu 24.04 - Screenshot 10

A complete Samba Server on Ubuntu 24.04 - Screenshot 11

A complete Samba Server on Ubuntu 24.04 - Screenshot 12

Restart of processes associated with the Samba Server and NetBIOS

After saving the changes and exiting the Samba configuration file, we must restart the services associated with it, with the command order:

systemctl restart smbd nmbd

A complete Samba Server on Ubuntu 24.04 - Screenshot 13

A complete Samba Server on Ubuntu 24.04 - Screenshot 14

Checking and validating the current Samba configuration

It is then recommended to test the changes made with the following command order:

testparm

Screenshot 15

Screenshot 16

Screenshot 17

Screenshot 18

Step 4: Local and remote verification of access to the created Samba resources

From the same Ubuntu 24.04 Server

Screenshot 19

Screenshot 20

From computers on the Internet

Screenshot 21

Screenshot 22

Screenshot 23

Screenshot 24

Screenshot 25

Finally, we can validate access and permissions granted to each folder, group and user created. And if everything is already working correctly, we can terminate the entire process until we are requested or require a new change.

Samba is the standard set of Windows interoperability programs for Linux and Unix.
Related article:
Samba 4.20 has already been released and comes with a large number of changes and new features

Summary 2023 - 2024

Summary

In summary, we hope that this new useful quick guide on implementing «a Samba Server on Ubuntu 24.04 », both simple and complete, allows many, with a few and accurate steps, to enjoy a small and efficient Samba storage service, about your any home or office. And in case you know other useful tips or advice to improve or complement this quick guide, we invite you to tell us about them via comments for everyone's knowledge and usefulness.

Lastly, remember to share this fun and interesting post with others, as well as visit the beginning of our «site" in Spanish. Or, in any other language (just by adding 2 letters to the end of our current URL, for example: ar, de, en, fr, ja, pt and ru, among many others) to find out more current content. Additionally, we invite you to join our Official Telegram channel to read and share more news, guides and tutorials from our website. And also, the next Alternative Telegram channel to learn more about the Linuxverse in general.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.