Centos 7 / Rhel 7: Install and Setup Samba Server (File Sharing)
Centos 7 / Rhel 7: Install and Setup Samba Server (File Sharing)
Centos 7 / Rhel 7: Install and Setup Samba Server (File Sharing)
In this tutorial we will learn, how to install and setup samba server ( file sharing server ) on
CentOS 7 and RHEL 7 (Red Hat Enterprise Linux 7) . Samba server is popularly use for
file and printer server and now a days it is also used as domain controller in network (like
Windows Active Directory).
Introduction of Samba
With arrival of Samba version 3, the definition of Samba server is changed. Now we call
samba is a free software suite licensed under GNU General Public Licenseversion 3. It is
populalry used for file and print services for all clients using the SMB/CIFS protocol.From
Samba version 3, we can integrate with a Windows Server domain, either as a Primary
Domain Controller (PDC) or as a domain member. It can also be part of an Active
Directory domain.
We will follow almost same steps as we did in our previous post on “How to install and
configure samba server in CentOS 6.3“. In CentOS 7 / RHEL 7 , a few steps are changed
because of some introuction of new commands and unavailabilty of packages in minimal
installed Operating System but logically everything is same.
Scenario: We will shared a directory called sharedrepo where we will permit user called
test and group called staff, can access the shared directory from Samba server and can
read write the files or directory.
137/tcp
137/udp
138/tcp
138/udp
139/udp
139/udp
445/tcp
445/udp
Create a directory called sharedrepo in / (main root) . This directory will be shared with
clients.
mkdir /sharedrepo
Step 3: Add a new group or can use existing group
To provide access on shared directory,Here we are adding new group called staff.
groupadd staff
Step 4: Change the group and permission of sharing folder
Here we are using /sharedrepo in samba server, hence group and permission are
changing for this directory.
useradd test
usermod -G staff test
smbpasswd -a test
Step 7: Edit /etc/samba/smb.conf file
First take backup of /etc/samba/smb.conf file then edit the smb.conf file.
cd /etc/samba/
cp -p smb.conf smb.conf.orig
And add the below given contents in last line of /etc/samba/smb.conf file.
vi /etc/samba/smb.conf
[sharedrepo]
comment = shared-directory
path = /sharedrepo
public = no
valid users = test, @staff
writable = yes
browseable = yes
create mask = 0765
Step 8: Allow network to connect with Samba Server
Edit these lines in /etc/samba/smb.conf . To allow network to reach samba server.
1.interfaces = Change the value of 192.168.56.0/24 with your subnet. And change the
ethernet value which is in used by your system and which you want to allow for traffic.
2. hosts allow = 192.168.56. is for subnet .Same rule applied to 127. which is for loopback.
workgroup = MYGROUP
Step 9 : Add services in /etc/services files
vi /etc/services
firewall-cmd --reload
Note: firewalld service must be runnig for above procedure. To start firewalld use systemd
command i.e systemctl start firewalld.service
In Windows Operatig System, open the run by pressing in combination of Start key +
r. Then type in this format \ip-address-of-samba-servershared-Direcory-
name
\192.168.56.102sharedrepo
Give username and password when it will ask.
2. Linux :
smbclient must be installed on system .
Server Comment
--------- -------
LOCALHOST Samba Server Version 4.1.1
Workgroup Master
--------- -------
MYGROUP LOCALHOST
sharad@linuxworld:~$
(B) Access using smb console
Sample output
sharad@linuxworld:~$ smbclient //192.168.56.102/sharedrepo -U test
Enter test's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: >
smb: > help
? allinfo altname archive backup
blocksize cancel case_sensitive cd chmod
chown close del dir du
echo exit get getfacl geteas
hardlink help history iosize lcd
link lock lowercase ls l
mask md mget mkdir more
mput newer notify open posix
posix_encrypt posix_open posix_mkdir posix_rmdir
posix_unlink
print prompt put pwd q
queue quit readlink rd
recurse
reget rename reput rm rmdir
showacls setea setmode stat
symlink
tar tarmode timeout translate unlock
volume vuid wdel logon
listconnect
showconnect tcon tdis tid logoff
.. !
smb: >
smb://192.168.56.102/