If you make use of a Linux server in your company, and do so for sharing files, then you know Samba. Samba is a very powerful and flexible interoperability suite of programs for Linux and Unix that allows you to share out directories to UNIX and non-UNIX platforms. Of course, Samba can do much more than that; but for now we’re going to focus on sharing. In particular, sharing for groups.
Adding groups into the Samba mix means you can gain a more efficient means of controlling what users can see what.
I’m going to walk you through the steps of creating a new Samba share, give a group access to that share, and then assign users to said group. I will assume you already have your Linux server up and running. I’ll be demonstrating on the Ubuntu Server platform.
In case you already haven’t done so, we must first install Samba. To do this, open up a terminal window and issue the command:
sudo apt-get install samba samba-client samba-common
Once the installation completes, you’ll want to enable Samba to start at boot with the following commands:
sudo systemctl enable smbd.service
âsudo systemctl enable nmbd.service
âsudo systemctl restart smbd.service
âsudo systemctl restart nmbd.service
Create the necessary directory and group
Before we configure Samba, let’s create the necessary directory and group. We’ll then add users to the group.
I’ll be creating a new share called editorial. Create a new directory with the command:
sudo mkdir -p /opt/editorial
Now let’s create the group editorial with the command:
sudo groupadd editorial
Now we change the group ownership and permissions of the directory with the commands:
sudo chgrp editorial /opt/editorial
âsudo chmod -R 770 /opt/editorial
Now we add users to the new group with the command:
sudo usermod -a -G editorial USER
Where USER is the username to add to the group.
If you ever need to remove a user from a group, this can be done with the command:
sudo deluser USER GROUP
Where USER is the username and GROUP is the group name.
Finally, we must add the users to Samba. This is done with the smbpasswd command like so:
sudo smbpasswd -a USER
âsudo smbpasswd -e USER
Where USER is the username to be added. The first command adds the user and the second command enables the user. When issuing the first of the above commands, you will be prompted to create a new Samba password for the user.
Now we come to the actual Samba configuration. The first thing we’re going to do is make a backup copy of our Samba configuration file. Issue the command:
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.BAK
Now create a new configuration file with the following command:
sudo nano /etc/samba/smb.conf
In this new file, we’ll add the following contents to share out our editorial directory to the group editorial (customize as needed):
âworkgroup = WORKGROUP
âserver string = Editorial Server
ânetbios name = Ubuntu
âsecurity = user
âmap to guest = bad user
âdns proxy = no
#### SHARES ####
âpath = /opt/editorial
âbrowsable = yes
âwritable = yes
âguest ok = yes
âread only = no
âvalid users = @editorial
Save and close that file. Restart Samba with the commands:
sudo systemctl restart smbd.service
âsudo systemctl restart nmbd.service
You can now point one of your machines to the newly configured Samba share. So long as the user is a member of the editorial group, they’ll be able to log on with their username and samba password.
Even more flexibility
By working with groups in Samba, you can make your admin life slightly easier, while making Samba more flexible. With this way you can add and remove users to the group with ease (which, in turn, would revoke their access to the Samba share).