Linux: Create a Samba share

Samba Server Setup

Linux: Create a Samba share
Photo by Mukund Kulur on Unsplash

Samba Server Setup

The following steps needs to be executed in the server which will be used as Samba share with sudo or as root.

Create the share path

First we need to create a path that will hold our data.

mkdir /smb

Fix clients rights

Read / Write access to everyone.

chmod 777 /smb

Install Samba packages

We need to install those packages to make the samba server work.

yum install samba -y

Edit smb.conf

Open /etc/samba/smb.conf and append the following to the end of the file and save changes.

[share] 
        browsable = yes 
        path = /smb 
        writable = yes

Test configuration

This little tool tests smb.conf for errors

testparm

Create the Samba share user and password

useradd smbuser 
smbpasswd -a smbuser

Start the Samba service

systemctl start smb 
systemctl enable smb

Set Up the Samba Clients

The following steps need to be executed on the machines that will act as Samba clients towards the server.

sudo yum install cifs-utils -y

Make a mount point

sudo mkdir /mnt/smb

Mount the Samba Share

sudo mount -t cifs //<SERVER_IP>/share /mnt/smb -o username=smbuser,password=<SMBPASSWD_PASS>

Test creating a file

cd /mnt/smb 
sudo touch 1.txt

Managing permissions

If only one user needs read/write access, you can make them the owner of the mounted directory using the option uid=<linux_username>:

sudo mount -t cifs //<SERVER_IP>/share /mnt/smb -o uid=<unix_username>,file_mode=0664,dir_mode=0775,username=smbuser,password=<SMBPASSWD_PASS>

If more than one user need read/write access, you can create a group, add the users to it:

addgroup new_group 
adduser user1 new_group 
adduser user2 new_group 
adduser user3 new_group

then mount the share using options gid, file_mode and dir_mode:

mount -t cifs //<SERVER_IP>/share -o gid=new_group,file_mode=0664,dir_mode=0775,username=smbuser,password=<SMBPASSWD_PASS>