SAMBA Server :- Complete Installation & Configuration

Last updated on March 12th, 2018 at 09:34 pm

Hello Linux-fanatics , in earlier tutorials about file sharing  we discussed about NFS & VSFTP . Both are used to share files among Linux file-systems. Now, we will discuss SAMBA server installation & configuration.

Samba server is used to share files with Windows system. We can also share printer services with it.

Let’s now setup a scenario for testing our server

Server                                                                         Client’s Machine

OS : Centos/RHEL  6 or 7                                                           OS :Windows 10 or Centos/RHEL 6 or 7

Hostname : smbserver.test.com                                             Hostname: windows.test.com

IP Address :192.168.1.100                                                        IP Address : 192.168.1.101

(Recommended Read: Integrating Active Directory with Linux (RHEL / CentOS))

 

Samba Server Installation

We need to install following packages to install Samba on our server

yum install samba samba-client samba-common

If we are using a Windows machine as client, we don’t need any special packages installed on windows machine but if using Centos/RHEL for testing, we need to install following packages

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

Now, our installation is done. We will now configure our shared folder.

 

Configuration

Firstly, we will create a user & a directory for share

useradd smbuser
mkdir /shared

Now, we will give all the permissions (777 read, write & execute for all users) to our /shared folder

chmod 777 /shared

We now have a folder to share & we will now make changes in configuration file to share the folder

vim /etc/samba/smb.conf

and at the bottom of the file , add following lines

[shared]
comment=Shared Directory
browseable=yes
path=/shared
public=no
writeable=yes
valid users=smbuser
create mask=0770

Now our shared folder is ready to be used but before we do that we need to assign password to our smbuser by using the following command

smbpasswd smbuser

and enter the desired password. We can now test our shared folder.

 

Testing on Linux machine

Firstly, we will check if the shared folder is accessible or not. This can be done by

smbclient –L 192.168.1.100 -U smbuser

If folder is accessible, you will 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 //192.168.1.100/shared /media/samba -o username=smbuser

where /media/samba is directory to access shared folder on our system. But this mount is a temporary  mount & will be unmounted as soon as we remount all partitions or restart our system.

In order to permanently mount it our system, we need to add following line in /etc/fstab file

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

/media/samba/.smbaccess is a hidden file with our credentials i.e.

username=smbuser

password= password for user

Now, our shared folder will be permanently mounted. Now, let’s test our samba share on a Windows machine.

 

Testing on Windows machine

On windows machine, open you “My Computer” & on top bar there should a option to map your drive (refer to screenshot below). Click on that option , then enter your drive address & credentials.

Upon successful verification of credentials, drive will show up with other local drives of your system.

Test it by creating a file. It should work fine.

Samba Windows share

 

Using Samba Server when Selinux is enabled

We might not be able to use our shared folder when Selinux is enabled as we need to set Boolean & security context values. We need to make changes to Selinux values by running following commands

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

 

This completes our tutorial on Samba Server installation & configuration. If facing any issue or have any queries/feedback, please use the comment box below.

 

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of you hard earned money:

Linux TechLab is thankful for your continued support.

Shusain

Passionate about Linux & open source. Loves to learn, read & write about Linux as well as new technologies.

You may also like...

Leave a Reply