How to install Samba server on CentOS 6

Part 1: Configuring anonymous share with samba server

To install the samba package,enter the following command:

sudo yum install samba samba-client samba-common

Check the version of installed samba software by using this command:

smbd --version

Configure the samba service, so that, it will start automatically at boot time:

sudo chkconfig smb on
sudo chkconfig nmb on

Disable the SELinux:

sudo nano /etc/selinux/config

Change SELinux from enforcing to disabled:


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

sudo iptables -I INPUT 4 -m state --state NEW -m udp -p udp --dport 137 -j ACCEPT
sudo iptables -I INPUT 5 -m state --state NEW -m udp -p udp --dport 138 -j ACCEPT
sudo iptables -I INPUT 6 -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
sudo service iptables save

Restart the Server!!!

Go to your Windows machine and use this command in order to check the WORKGROUP name:

net config workstation

It will show the output, something like this:

Backup the smb.conf file, then delete it and create the new one:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
sudo rm /etc/samba/smb.conf
sudo touch /etc/samba/smb.conf
sudo nano /etc/samba/smb.conf

Add these lines, in your smb.conf file (or change it according to your requirement):

#======================= Global Settings =====================================
 workgroup = WORKGROUP
 security = share
 map to guest = bad user
#============================ Share Definitions ==============================
 path = /samba/share
 browsable =yes
 writable = yes
 guest ok = yes
 read only = no

Save the smb.conf file and restart the service:

sudo service smb restart
sudo service nmb restart

Access the samba share from windows (where centos is the name of my samba server):

wao, we are able to access the samba share successfully :-)

Let’s try to create something, inside the share folder:

Error, we cannot create anything inside the share folder :-(

Check the current permission on the samba share:

cd /samba/
ls -l

Change it, in such a way that everyone can read and write it(Check it, that it is allowed in your environment or not):

sudo chmod -R 0777 share
ls -l

Try to create something again, inside the share folder:

Verify the newly created file on samba server:

cd share/
ls -l

Part 2: Add and manage users and groups

Add a group in your CentOS server (in my case smbgrp):

sudo groupadd smbgrp

Create a new share, set the permission on the share:

cd /samba/
sudo mkdir secure
sudo chown -R arbab:smbgrp secure/ 
ls -l 
sudo chmod -R 0770 secure/
ls -l

Add the user to the samba group and create samba password:

sudo usermod -a -G smbgrp arbab
sudo smbpasswd -a arbab

Edit the smb.conf file:

sudo nano /etc/samba/smb.conf

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

path = /samba/secure
 valid users = @smbgrp
 guest ok = no
 writable = yes
 browsable = yes

Restart the samba service:

sudo service smb restart
sudo service nmb restart

Check the syntax error with testparm:

sudo testparm

Testing from Windows Machine:

Verification from CentOS server:

cd /samba/secure/
ls -l 

Hope this will help you!

Please Remember me in your prayers!

Enjoy :-)

34 responses to “How to install Samba server on CentOS 6

  1. Mr. Sushant Wankhede August 23, 2012 at 6:41 pm

    Its Awesome. I surf so many articles for this matter, but found this the BEST. I will give 10/10 to this.Thanks Sir.

  2. Pingback: Install LDAP and SAMBA for user management

  3. Pingback: Samba Server not Working - Page 2

  4. Pingback: Samba Server not Working - Page 2

  5. Suman Saha November 9, 2012 at 1:40 am

    This the best and many thanks to you.

  6. Pingback: Samba in CentOS |

  7. DaveC November 12, 2012 at 5:48 pm

    I’m very much a part time linux admin and this looked like a nice article until I got to the bit about “Change SELinux from enforcing to disabled:”. Doing this, then changing the iptables and rebooting caused my linux Centos6 system to become completely unbootable. I had to dd enforcing=0 to my boot string just to get into the system to change it back. And after 2 hours it is still relabeling…My own fault for not understand the SELinux system but still annoying😦

    • Arbab November 12, 2012 at 10:07 pm

      DaveC, I never ever had a problem of this kind………I disabled the SELinux on almost more than 100 linux but never faced this kind of problem…….very strange for me

      • DaveC November 13, 2012 at 1:51 pm

        Never did anything else so i would just say to people be careful and be sure you know how to get back in if your going to change selinux=disabled😉 thanks by the way, this was a very well written and informative article.

  8. cro November 30, 2012 at 3:21 am

    Hi very nice tuto.

    have you heard anything about sharing folder from centos to windows where the share folder is located under an LVM partition?

    I am asking that because it does work when you share a “normal” folder but it doesn’t when the share is located on a LVM partition?

    At least it doesn’t for me ;-p

  9. Everett January 5, 2013 at 1:36 am

    Excellent article! Beware of where you put the /samba/share directory on the Linux VM. If you put it in /home/user, the Win7 host will not be able to access it.

  10. Jhon Edison January 15, 2013 at 12:23 am

    Very x 10e10 thank’s!!!! you saved me .. was the best article I’ve found. Greetings from Colombia.

  11. angelo Cavallet January 30, 2013 at 2:46 am

    very nice😀

  12. Kyle February 4, 2013 at 9:24 am

    when i go to access the share from my windows machine it gives me an error saying windows cannot access and gives me the share path and i know it is typed in correctly the error code is also 0x80070043 can anyone help me

  13. Thankful for this guide March 13, 2013 at 6:02 pm

    cheers for this guide!

  14. Pingback: How to install Samba server on CentOS 6 | Enforce Security

  15. Pingback: CentOS 6 : Samba Server | Muhammad Bintang's Weblog

  16. Pingback: Instalar un SO remotamente mediante IPMI | Hello, IT.

  17. Anonymous June 18, 2013 at 4:34 pm

    Anonymous : when i access the created from a linux machine , even if i enter the user name and password it doesnt works for the secure folder but for windows its works fine.. whats the issue ?

  18. alex September 17, 2013 at 4:03 pm

    hello all, thanks for great and fast tutorial. I was wondering if it is possible to have another one for using a different ldap server to authenticate users for the samba server . i have tried to do it and i get

    check_sam_security: make_server_info_sam() failed with ‘NT_STATUS_NO_SUCH_USER’
    from samba log

  19. Anonymous September 29, 2013 at 3:38 am

    Wonderful tutorial. It was very helpful. I run it on a Centos 6.4 and needed to add an additional rule to iptables:
    -A INPUT -p tcp -m state –state NEW -m tcp -dport 445 -j ACCEPT
    Now I can browse the share from any client Linux and Windows.

  20. anon January 29, 2014 at 3:54 pm

    Thanks for this dude…it helped me a lot. Concise, simple and to the point!

  21. stanis February 19, 2014 at 4:17 pm

    Thank you a lot ^)

  22. Tharsan February 25, 2014 at 7:45 am

    great job bro !!

  23. April 7, 2014 at 5:58 pm

    Thank you so much. I was able to share folders, but by only using Host Only adpter. Does this even work with NAT Adapter

  24. Endro Rhs April 23, 2014 at 5:24 pm

    Amazing, my problem is resolved for 2 months with this tutorial completed within 30 minutes

  25. May 2, 2014 at 8:10 pm

    Extremely Helpful. Thanks!

  26. Michael August 14, 2014 at 3:12 am

    What a fantastic SAMBA guide – never seen one so easy.

    So, to take this one step further, if we have a bunch of linux users already on the system and wanted them to have full access to their own home/user directories would I add the following to the smb.conf file:

    comment = Home Directories
    browseable = no
    writable = yes
    guest ok = no
    ; valid users = %S
    ; valid users = MYDOMAIN\%S

  27. Gagan Pal August 24, 2014 at 3:59 am

    Very nice!! smooth and steady article!

  28. btissam April 2, 2015 at 8:20 pm

    It work perfectly. Thank youuuuuuuuu

  29. Pingback: Installing Samba in Centos 6.5 | SkrinHitam

  30. Jonas May 12, 2016 at 12:39 am

    The setting “security = share” leads to an error during startup of the service. I’m using samba 4.2.10. I removed the line and everything’s working fine.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: