Setup Samba Server for CentOS

Samba is an open source implementation of the Server Message Block (SMB) protocol. It allows the networking of Microsoft Windows®, Linux, UNIX, and other operating systems together, enabling access to Windows-based file and printer shares

A. Samba Server Basic

Step 1. Install samba server

yum -y install samba samba-client samba-common

Step 2. Check version samba server

smbd --version

Step 3. Configure the samba service

chkconfig smb on
chkconfig nmb on

Step 4. Disable the SELinux

vi /etc/selinux/config
# change SELINUX=enforcing to SELINUX=disabled

Step 5. Add these Iptables rules, so that samba server will work perfectly

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

Step 6. Restart the Server!!!

Step 7. Go to your Windows machine, check the WORKGROUP name

net config workstation

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

cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
rm -rf /etc/samba/smb.conf
touch /etc/samba/smb.conf
vi /etc/samba/smb.conf

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

#===== Global Settings =====
workgroup = WORKGROUP
security = share
#===== Share Definitions =====
path = /path/to/shared
browsable = yes
writable = yes
guest ok = yes
read only = no
create mask = 0775
directory mask = 0775

Step 10. Save the smb.conf file and restart the service

service smb restart
service nmb restart

Step 11. Check the current permission on the samba share

cd /path/to/parent/directory/of/share
ls -l

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

chcon -Rt samba_share_t /path/to/parent/directory/of/share/
# if still the error persists, then try changing the mode of folder to 0777
chmod -R 0777 /path/to/parent/directory/of/share
ls -l

Step 13. Access the samba share from Windows (where is the ip of samba server)


B. Samba Server Advance (Add and manage users and groups)

Step 1. Add a group in your CentOS server (in my case smbgrp)

groupadd smbgrp

Step 2. Create a new share, set the permission on the share

cd /path/to/parent/directory/of/share
mkdir secure
chown -R arbab:smbgrp secure/
ls -l
chmod -R 0770 secure/
ls -l

Step 3. Add the user to the samba group and create samba password

usermod -a -G smbgrp arbab
smbpasswd -a arbab

Step 4. Edit the smb.conf file

vi /etc/samba/smb.conf

Step 5. Add the newly created samba share in smb.conf file

path = /path/to/secure/share
valid users = @smbgrp
guest ok = no
writable = yes
browsable = yes
create mask = 0775
directory mask = 0775

Step 6. Restart the samba service

sudo service smb restart
sudo service nmb restart

Step 7. Check the syntax error with testparm



Popular posts from this blog