Samba Server Configuration on RHEL7/Centos7/Fedora22 Step-by-Step Config Guide

Accessing Network Storage with SMB

samba allow Linux system to share files and printers across a network connection. By using its SMB(server message block) protocol, you Linux box can appear in windows network neighborhood or my network places just like any other windows machine. You can share files this way, as well as printers.

Samba is an Implementation of a common Internet file system(CIFS, also know as SMB) protocol server that can be run on almost every variant of UNIX in existence. Microsoft clients will use this protocol to access files and printers located on your UNIX box just as if it were a native window server.


Outline of Samba server:

Package                   : Samba, samba-common, samba-client(For clients), cifs-utils
File system             :  CIFS (common Internet file system)
Configuration File : /etc/samba/smb.conf
Usage                       : Used for sharing files and directories in the network between different platforms, like Linux-windows.
Daemon                   :  smbd (It provides the file and printer sharing services.), nmbd (It provides the NetBIOS-to-IP-address name service)

My setup:

  • Samba server ip add. and hostname: (server1).
  • samba client ip add. and hostname(Linux): (Client1).
  • samba client ip add. and hostname(Window):

Configuration of samba server

There is few steps to implement the samba server.

1) Check and Install the Samba Package, if not installed.
#rpm -qa samba

[root@server1 ~]# rpm -qa samba
[root@server1 ~]#

Install the Package using yum.
#yum install samba samba-client samba-common cifs-utils -y

If you are not configured yum server, refer the link Configure the Yum Server in Centos7/RHEL7/Fedora22

[root@server1 ~]# yum install samba samba-client samba-common cifs-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package cifs-utils.x86_64 0:6.2-7.el7 will be installed

Install  4 Packages (+11 Dependent packages)

Total download size: 7.6 M
Installed size: 24 M
Is this ok [y/d/N]: y

2) Adding a system users in group and make a Directory,which will be shared.

We adding a “sambagrp” group ( or you can use existing group.) in which two users are added (i.e anil, shilpa).

[root@server1 ~]# groupadd sambagrp
[root@server1 ~]# useradd anil
[root@server1 ~]# useradd shilpa
[root@server1 ~]# usermod -a -G sambagrp anil
[root@server1 ~]# usermod -a -G sambagrp shilpa

Make a directory.
#mkdir /Sambadir1   

[root@server1 ~]# mkdir /Sambadir1

Give access to the new directory and change the group.

[root@server1 ~]# chmod 0770 /Sambadir1
[root@server1 ~]# chgrp sambagrp /Sambadir1

If your selinux is enabled, Change the sebooleum parameter as shown below,

[root@server1 ~]# setsebool -P samba_export_all_ro=1 samba_export_all_rw=1
[root@server1 ~]#

Change the context of the directory and change it according to samba.

[root@server1 ~]# semanage fcontext -a -t  samba_share_t "/Sambadir1(/.*)?"
[root@server1 ~]# restorecon -R -v /Sambadir1
restorecon reset /Sambadir1 context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:samba_share_t:s0
[root@server1 ~]#

Note: If you faced  “semanage: command not found” error.Then install the policycoreutils-python packages using yum install policycoreutils-python -y

3) Add the samba service to the firewall.

[root@server1 ~]# firewall-cmd --permanent --add-service=samba
[root@server1 ~]# firewall-cmd --reload
[root@server1 ~]#

4) Go to configuration file (i.e /etc/samba/smb.conf ) and make the following changes.

First take the backup smb.conf file.

[root@server1 ~]# cp -v /etc/samba/smb.conf /etc/samba/smb.conf.bak
‘/etc/samba/smb.conf’ -> ‘/etc/samba/smb.conf.bak’
[root@server1 ~]#

Edit the /etc/samba/smb.conf file.

#vim /etc/samba/smb.conf

comment=Samba Shared
force group=sambagrp
valid users=@sambagrp
write list=@sambagrp

Note: For windows users, if your all systems in your network are using different WORKGROUP name edit the given below line in smb.conf with your workgroup name. Windows system by default uses the WORKGROUP as WORKGROUP. Try first without changing the WORKGROUP name,if required do the changes.

Check the syntax of the configuration file:

[root@server1 ~]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[SambaGroup]"
Loaded services file OK.

4) Create a user or use any existing user.

Create a new user or use any exiting user who will be allowed to log in as samba user, add that user to samba user.
As we have existed user “anil” and “shilpa”, let’s just make it samba user.

[root@server1 ~]# smbpasswd -a anil
New SMB password:
Retype new SMB password:
Added user anil.
[root@server1 ~]# smbpasswd -a shilpa
New SMB password:
Retype new SMB password:
Added user shilpa.
[root@server1 ~]#

Note: To delete the samba user use #smbpasswd -x <user name>

To check the all samba users

#pdbedit -L

[root@server1 ~]# pdbedit -L
[root@server1 ~]#

6) Start and enable the samba services.

Note: “enable” option is used to Activate the Samba services at boot.

[root@server1 ~]# systemctl start smb 
[root@server1 ~]# systemctl enable smb 
Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/smb.service
[root@server1 ~]#

Now make sure the share is actually available to network clients:

[root@server1 ~]# smbclient -L // -U anil
Enter user1's password: 
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Sharename       Type      Comment
    ---------       ----      -------
    SambaGroup      Disk      Samba Shared
    IPC$            IPC       IPC Service (Samba Server Version 4.2.3)
    user1           Disk      Home Directories
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------

How to connect window client with samba server

1) Connect from window to the samba server.

To connect from window to samba server, right click on “My computer” icon and select “Map network drive” option.


Specify the samba drive address as //, and press finish button, refer above image.

3) How to connect to Samba Server from client.

Now, Enter your samba server credentials for login and press “ok” button.


4) After mounting Create a some files.



How to connect Linux client with samba server

1) Make sure the samba client is installed on client machine.

# rpm -qa samba*

[root@client1 ~]# rpm -qa samba
[root@client1 ~]# rpm -qa samba*
[root@client1 ~]#

If samba is not Installed then install using below command.

[root@client1 ~]# yum install samba samba-client samba-common cifs-utils -y

2) Make sure the Samba share is accessible from this client.

[root@client1 ~]# smbclient -L // -U anil
Enter user1's password: 
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Sharename       Type      Comment
    ---------       ----      -------
    SambaGroup      Disk      Samba Shared
    IPC$            IPC       IPC Service (Samba Server Version 4.2.3)
    user1           Disk      Home Directories
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------

3) Mount the samba drive.

First make the mount directory and mount the samba drive on client machine, refer below commands.

[root@client1 ~]# mkdir /mnt/sambashareddir
[root@client1 ~]# mount -o username=anil //  /mnt/sambashareddir  
Password for anil@//*****
[root@client1 ~]# df -h  /mnt/sambashareddir/
Filesystem                 Size  Used Avail Use% Mounted on
//  6.7G  994M  5.7G  15% /mnt/sambashareddir
[root@client1 ~]#

To make permanent mount of “/mnt/sambashareddir” directory edit “/etc/fstab” file as follows.

# vim /etc/fstab

//     /mnt/sambashareddir    cifs   credentials=/root/.smbcredentials,defaults    0 0


Create a hidden file (i.e /root/.smbcredentials) and edit that file with your samba username and password.

# vim /root/.smbcredentials



Note: Change the permissions and ownership of /root/.smbcredentials file and set to 600 and root:root,respectively.

[root@client1 ~]# chmod 600 /root/.smbcredentials ; chown root:root /root/.smbcredentials 
[root@client1 ~]# ll /root/.smbcredentials 
-rw-------. 1 root root 30 Oct  7 02:46 /root/.smbcredentials
[root@client1 ~]#

Go to mount point and Lets see to add some files.

[root@client1 ~]# cd /mnt/sambashareddir/
[root@client1 sambashareddir]# touch file{1..5}
[root@client1 sambashareddir]# ls
file1  file2  file3  file4  file5
[root@client1 sambashareddir]#


Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Sudhir Kushwah Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

newest oldest most voted
Notify of
Sudhir Kushwah
Sudhir Kushwah

very nice