Easy Samba installation on RHEL/CentOS 7

Photo of author

By rasho

Samba is a client/server system that implements network resource sharing for Linux and other UNIX computers. With Samba, UNIX files and printers can be shared with Windows clients and vice versa. Samba supports the Session Message Block (SMB) protocol. Nearly all Windows computers include SMB support with their internal network subsystems (NetBIOS in particular).
With an appropriately-configured Samba server on Linux, Windows clients can map drives to the Linux filesystems. Likewise, theSamba client on UNIX can connect to Windows shares by their UNC name. Although differences among various operating systems (such as filesystem naming conventions, end-of-line conventions, and authentication) can limit interoperability, Samba offers a generally serviceable mechanism for resource sharing on a heterogenous network.
In this tutorial we will show you how to install and configure Samba server on RHEL and CentOS 7 linux.

Install and configure Samba on Rhel/CentOS 7

To install samba packages enter following command:

yum install samba samba-client samba-common -y

Now configure samba edit the file /etc/samba/smb.conf

mv /etc/samba/smb.conf /etc/samba/smb.conf.bkp
vi /etc/samba/smb.conf

and paste following line:

[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = centos
security = user
map to guest = bad user
dns proxy = no
#============================ Share Definitions ==============================
[Anonymous]
path = /samba/anonymous
browsable =yes
writable = yes
guest ok = yes
read only = no

Save the smb.conf file and restart the service:

mkdir -p /samba/anonymous
systemctl enable smb.service
systemctl enable nmb.service
systemctl restart smb.service
systemctl restart nmb.service

Add these Iptables rules, so that samba will work perfectly:

firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload

Change permission for samba share:

chmod -R 0755 anonymous/
chown -R nobody:nobody anonymous/

Further we need to allow the selinux for the samba configuration as follows:

chcon -t samba_share_t anonymous/

Now you can access the Centos 7.0 sharing in windows as follows, go to the Run prompt and type \centos :

Access to samba share
Access to samba share


Now anonymous user can browse & create new text documents:

Secured samba server

For this I will create a group smbgrp & user rasho to access the samba server with proper authentication

useradd rasho
groupadd smbgrp
usermod -a -G smbgrp rasho
smbpasswd -a rasho
[root@localhost]# smbpasswd -a rasho
New SMB password:  YOUR SAMBA PASS
Retype new SMB password:   REPEAT YOUR SAMBA PASS
Added user rasho.

[ads]
Create a new share, set the permission on the share:

mkdir /home/secure
chown -R rasho:smbgrp /home/secure/
chmod -R 0770 /home/secure/
chcon -t samba_share_t /home/secure/

Again edit the configuration file as :

vi /etc/samba/smb.conf

Add the newly created samba share in smb.conf file:

[Secure]
path = /home/secure
valid users = @smbgrp
guest ok = no
writable = yes
browsable = yes

Screenshot from 2014-09-23 22:47:11
Restart the samba service:

systemctl restart smb.service
systemctl restart nmb.service

Now at windows machine check the folder now with the proper credentials

Open samba sharing
Open samba sharing

Enter your samba user and passa
Enter your samba user and passa

Create new text documents:
Create new text documents in your shared folder
Create new text documents in your shared folder

That is all!

22 thoughts on “Easy Samba installation on RHEL/CentOS 7”

  1. Thanks you so much rasho. I’m a Microsoft ( infected= addicted) and a greenhorn in Linux-World. Nevertheless your tutorial helped me a lot, thank you for the explanation for dummies ( Screenshot) .

    Reply
  2. Awesome. Thanks a lot!
    The only thing I had to configure afterwards was to make the secured share to be mounted persistently by using the /etc/fstab file.

    Reply
  3. I have SME Server 9.0 and in these server total fix 6 HDD OS HDD is different other 5 HDD is on Raid 5 today morning i got the error
    The superblock could not be read or dose not describe a correct ext2 filesystem e4fsck -b 8193 ( Device )

    Please help what should i do

    Reply
  4. Which is best Free software updates linux distribution which can install samba server,jdk,jre,tomcat,mysql,apache tomcat,glassfish to install. why because i am not able to install samba server in redhat 5/6 version linux- on trying installing i getting error ‘usr/bin/install – cannot execute binary file’

    Reply
  5. Dear All,
    My issue is , my samba share is working fine but Windows Xp and Windows server 2003 machines can not access the share. it gives the error bad username and password. Please help.

    Reply
    • Try setting this up on your Windows XP and other Windows problematic machines:
      ——————————–
      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
      “LMCompatibilityLevel”=dword:00000005
      ——————————–

      if that doesn’t work,

      # add these lines to smb.conf
      lm announce = no
      lanman auth = no
      ntlm auth = no
      client lanman auth = no
      client ntlmv2 auth = yes
      # ——————————————

      Reply
  6. Unable to share already existing directory , if i create the folder using the mkdir /home/secure , then it is working. please help

    Reply
  7. a user which member of smbgrp , wanna access Anonymous share as a guest user even he able to access secure share folder.
    How can we do sir?

    Reply

Leave a Comment