Guide to creating a shared folder using SAMBA server

Samba is an open source software, based on CIFS (Common Internet File System) that can run on Unix/Linux distributions & makes it possible to communicate with Windows machines. We use samba server mainly to share files & folder with windows client machine but we can also share print services using samba and for authentication & authorization as well.
In this tutorial, we will learn to create a samba server & will share files with a windows client machine using samba. We will start out with installing samba server & related packages on server & then on client, next we  will add a samba user & configure a shared directory & lastly we will test the shared directory on both, Linux & Windows client machine. Process is mentioned in detail below,


Before we can start installing samba server & configure a shared directory, we will need

  • A system with RHEL/CentOS 7 installed for samba server installation,
  • A windows client machine & a Linux client machine.


We will install samba our system by running the following command,

$ yum install samba samba-client samba-common

For the RHEL client machine, we will require the following packages installed,

$ yum install samba samba-client samba-common cifs-utils

But for the windows client machine, we don’t require any extra packages installed. Once the installation is complete for samba server & client, we will configure the shared folder.

Configuring shared folder

Firstly, create an user for samba access

$ useradd sambauser

Next, create a new directory to share with samba

$ mkdir /shared_dir

then assign the appropriate permissions i.e. 777 (read, write & execute for all users) to /shared_dir folder

$ chmod 777 /shared_dir

Next step is to create a configuration entry for the folder to be shared in ‘/etc/samba/smb.conf’

$ vim /etc/samba/smb.conf

and at the bottom of the file , add following lines

comment=Shared Directory
valid users=sambauser
create mask=0770

Save & exit the file. Last thing we need to do before we can use the shared directory, is to assign a password to the sambauser. To do so, run

$ smbpasswd sambauser

and enter the desired password. Restart the samba server to implement the changes,

$ systemcctl restart samba

Testing on Linux machine

Open terminal for the Linux machine & execute the follwoing command to check if the shared folder is accessible,

$ smbclient –L -U sambauser

we should see output on screen with details of shared folder. Once it’s confirmed that folder is accessible, we will mount it on our system

$ mount // /mnt/samba -o username=sambauser

where /mnt/samba is directory to mount shared folder on our system. This is a temporary mount & in order to permanently mount it our system, we need to add following line in /etc/fstab file

$ vi /etc/fstab

// /media/samba cifs credentials=/media/samba/.smbaccess,defaults 0 0

/media/samba/.smbaccess is a hidden file with our credentials i.e.
password= password for user

Now, let’s test our samba share on a Windows machine.

Testing on Windows machine

Open ‘Run’ by searching it after pressing ‘Windows’ key or by pressing ‘Windows + R’ key. Once the run is opened, enter the IP address of samba share prefixed with \\’ i.e

$ \\

We will be asked to provide username & password, once the user has been authentiicated the shared folder will open.

Using Samba Server when Selinux is enabled

If you need to use samba when SeLinux for the system is in enabled state, then we need use some booleans to make sure that the samba works fine. These are

setsebool -P samba_export_all_ro=1 samba_export_all_rw=1
getsebool –a | grep samba_export
semanage fcontext –at samba_share_t “/shared_dir(/.*)?”
restorecon /shared_dir

Shujat Husain

A continuous learner with several years of experience in linux environment. I love to read, learn & write about Linux & new technologies. And I also write at

What is in your mind, about this post ? Leave a Reply

  Our next learning article is ready, subscribe it in your email

What is your Learning Goal for Next Six Months ? Talk to us