How to configure Samba Server in Linux



Samba Server is using the Server Message Block (SMB) protocol to allow Linux systems to interface with Windows systems in the network. Samba is licensed under the GNU Public License and is open source.

In this article, we will be known about the installation of Samba Server

We can simply install the samba as follows

#yum –y install samba

Now create a Directory and files to share

[root@localhost ~]# mkdir /sambashare
[root@localhost ~]# chmod 770 /sambashare/
[root@localhost ~]# cd /sambashare
[root@localhost sambashare]# touch test1 test2 test3
[root@localhost sambashare]# ls
test1  test2  test3
[root@localhost sambashare]#

Now create the samba user

We have to add users to samba database in order to access Samba shared files and resources

[root@localhost ~]# useradd test
[root@localhost ~]# smbpasswd test -a
New SMB password:
Retype new SMB password:
Added user test.

Now create a group for samba users and then add the users to it.

[root@localhost ~]# groupadd smbusers
[root@localhost ~]# chown :smbusers /sambashare
[root@localhost ~]# usermod -G smbusers test

Now configure the smb.conf file

All the samba configuration is done in the /etc/samba/smb.conf file. There are two parts in the smb.conf file.

  1. The first part is the global section, In this section, The generic properties of the Samba service are defined.
  2. The second part contains the share definitions, In this part share specific settings are defined. There ate two special shares may be enabled i.e
    • [homes] contains default values for accessing home directories that are shared through Samba.
    • [printers] is used to provide access to printers that are shared using the CUPS printing system.

In the global section, we can configure the basic samba parameters likeWorkgroup, security level, host allow etc.

creating shares

To create  the shares, we need to add the section near to the end of the smb.conf file

Path The path on the Linux file system of the shared directory.

writable Enables write access on a share. If set to yes, all authenticated users have the write access (if also permitted by Linux permissions). If set to no, a comma separated write list of users or groups can be used to specify names of users and groups that have write permissions on the share.

read only Setting the read-only parameter to no has the same effect as setting writable to yes.

write list Contains a comma separated list of users or groups that have write access, even if writable is set to no. To use groups, put a @ or + in front of the group name.

valid users Use to limit access to the share to listed users only. By default, all users have access to the share.

comment Use to specify a comment. This comment is displayed to users before connecting to the share.

guest ok Allows access to the guest account. Be careful using this because it basically bypasses all security settings. This parameter is required on some administrative shares though.

browseable Allows browse access to shares, which means that users can navigate through the share structure to see items available in the share. Make sure to disable on the [home] share.

Now add the share to your configuration file as follows

comment = My Samba Share
path = /sambashare/
write list = @smbusers

After completion fo adding these lines save the file and run the following command to check for errors


Now configure the firewall to accept the connection for samba server as follows

#firewall-cmd --permanent --add-service=samba
#firewall-cmd --reload

Now configure the SELinux for Samba server as follows

#semanage fcontext -a -t samba_share_t "/sambashare(/.*)?"
#restorecon -R -v /sambashare/

Now enable and start the samba server as follows

#systemctl enable smb
#systemctl start smb

Now check it in windows system

Now Enjoy Samba server.



Previous articleOpencart installation on Linux
Next articleMoodle installation on Linux
This is Naga Ramesh Reddy from Vijayawada (India).I have 4+ years of experience in System and Network Administration field. I like to read and write about Linux, Cisco, Microsoft technologies and the latest software releases. Particularly I am mad about Linux flavors like Centos, RHEL, Ubuntu and Linux Mint.