{"id":127,"date":"2023-03-19T08:47:18","date_gmt":"2023-03-19T07:47:18","guid":{"rendered":"http:\/\/10.4.44.99:10084\/?p=127"},"modified":"2023-03-19T08:47:18","modified_gmt":"2023-03-19T07:47:18","slug":"centos-7-install-and-setup-samba-server-file-sharing","status":"publish","type":"post","link":"https:\/\/www.winni.at\/wordpress\/?p=127","title":{"rendered":"Centos 7 | Install and setup samba server ( file sharing)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Project URL :<\/strong>&nbsp;<a href=\"http:\/\/www.samba.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/www.samba.org\/<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Introduction of Samba<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With arrival of Samba version 3, the definition of Samba server is changed. Now we call samba is a free software suite licensed under&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/GNU_General_Public_License#Compatibility_and_multi-licensing\" target=\"_blank\" rel=\"noreferrer noopener\">GNU General Public License<\/a>&nbsp;version 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will follow almost same steps as we did in our previous post on \u201c<a href=\"http:\/\/sharadchhetri.com\/2013\/02\/17\/how-to-install-and-configure-samba-server-in-centos-6\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to install and configure samba server in CentOS 6.3<\/a>\u201c. 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Scenario:<\/strong>&nbsp;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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Details of Samba server on which practical applied<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Operating System :<\/strong>&nbsp;CentOS 7<br><strong>Arch :<\/strong>&nbsp;x86_64<br><strong>Samba Version :<\/strong>&nbsp;Samba 4.1.1 (Default from CentOS repo)<br><strong>Kernel Versio :<\/strong>&nbsp;3.10.0-123.el7.x86_64<br><strong>IP Address :<\/strong>&nbsp;192.168.56.102<br><strong>Network Subnet :<\/strong>&nbsp;192.168.56.0\/24 or can be written also as 192.168.56.0\/255.255.255.0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>NOTE:<\/strong>&nbsp;CentOS 7 is installed with minimal packages (minimal installed)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Samba Server port numbers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">137\/tcp<br>137\/udp<br>138\/tcp<br>138\/udp<br>139\/udp<br>139\/udp<br>445\/tcp<br>445\/udp<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Daemon used in Samba server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Samba services are implemented as two daemons:<br><strong>1. smbd<\/strong>, It provides the file and printer sharing services.<br><strong>2. nmbd<\/strong>&nbsp;It provides the NetBIOS-to-IP-address name service. NetBIOS over TCP\/IP requires some method for mapping NetBIOS computer names to the IP addresses of a TCP\/IP network.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to install and configure samba server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 1 : Use yum command to install samba packages<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(a) policycoreutils-python = For semanage command (Read&nbsp;<a href=\"http:\/\/sharadchhetri.com\/2014\/10\/07\/semanage-command-found-centos-7-rhel-7\/\">semanage command not found<\/a>)<br>(b) samba-client : For smbpasswd (Read&nbsp;<a href=\"http:\/\/sharadchhetri.com\/2014\/10\/07\/smbpasswd-command-found-centos-7-rhel-7\/\" target=\"_blank\" rel=\"noreferrer noopener\">smbpasswd command not found<\/a>)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(c) cups-libs : For printer service<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(d) samba and samba-commons : For Samba server<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">yum install -y samba samba-commons cups-libs policycoreutils-python samba-client<br><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 2: create a directory<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a directory called sharedrepo in \/ (main root) . This directory will be shared with clients.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir \/sharedrepo<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 3: Add a new group or can use existing group<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To provide access on shared directory,Here we are adding new group called staff.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">groupadd staff<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 4: Change the group and permission of sharing folder<\/strong><br>Here we are using \/sharedrepo in samba server, hence group and permission are changing for this directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chgrp -R staff \/sharedrepo\nchmod -R 777 \/sharedrepo<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 5: Change the selinux security context<\/strong><br>Change the selinux security context on sharing directory and set the selinux boolean value for samba.<br>You can skip this step in case you&nbsp;<a href=\"http:\/\/sharadchhetri.com\/2013\/02\/27\/how-to-disable-selinux-in-red-hat-or-centos\/\" target=\"_blank\" rel=\"noreferrer noopener\">disable selinux<\/a>&nbsp;on system<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chcon -R -t samba_share_t \/sharedrepo\/\nsemanage fcontext -a -t samba_share_t \/sharedrepo\/\nsetsebool -P samba_enable_home_dirs on<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 6: create user, add into group and set samba password<\/strong><br>create user and add them in group called staff. And set the samba password for this user.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">useradd test\nusermod -G staff test\nsmbpasswd -a test<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 7: Edit \/etc\/samba\/smb.conf file<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First take backup of \/etc\/samba\/smb.conf file then edit the smb.conf file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/etc\/samba\/\ncp -p smb.conf smb.conf.orig<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And add the below given contents&nbsp;in last line&nbsp;of \/etc\/samba\/smb.conf file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi \/etc\/samba\/smb.conf<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">[sharedrepo]\ncomment = shared-directory\npath = \/sharedrepo\npublic = no\nvalid users = test, @staff\nwritable = yes\nbrowseable = yes\ncreate mask = 0765<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 8: Allow network to connect with Samba Server<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Edit these lines in \/etc\/samba\/smb.conf . To allow network to reach samba server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.interfaces =&nbsp;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.<br>2. hosts allow =&nbsp;192.168.56. is for subnet .Same rule applied to 127. which is for loopback<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">interfaces = lo enp0s8 192.168.56.00\/24\nhosts allow = 127. 192.168.56.<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong>&nbsp;For windows users,if your all PC in your network are using different WORKGROUP name edit the given below line in smb.conf with your workgroup name. Windows system bydefault uses the WORKGROUP as WORKGROUP. Try first without changing the WORKGROUP name,if required do the changes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">workgroup = MYGROUP<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 9 : Add services in \/etc\/services files<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi \/etc\/services\n \nnetbios-ns\t137\/tcp\t# netbios name service\nnetbios-ns\t137\/udp\t# netbios name service\nnetbios-dgm\t138\/tcp\t# netbios datagram service\nnetbios-dgm\t138\/udp\t# netbios datagram service\nnetbios-ssn\t139\/udp\t# netbios session service\nnetbios-ssn\t139\/udp\t# netbios session service<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 11: Now start the smb and nmb services.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl start smb.service\nsystemctl start nmb.service<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 11 : Enable smb and nmb service at booting of system<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl enable smb.service\nsystemctl enable nmb.service<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Below given section is referece:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@localhost ~]# systemctl enable nmb.service\nln -s '\/usr\/lib\/systemd\/system\/nmb.service' '\/etc\/systemd\/system\/multi-user.target.wants\/nmb.service'\n[root@localhost ~]# \n[root@localhost ~]# systemctl enable smb.service\nln -s '\/usr\/lib\/systemd\/system\/smb.service' '\/etc\/systemd\/system\/multi-user.target.wants\/smb.service'\n[root@localhost ~]#<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 12 : Add firewalld rule to allow samba<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In RHEL 7\/ CentOS 7, firewalld is shipped by default. Now onwards we recommend you to use firewalld instead of iptables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here, we are allowing source network 192.168.56.0\/24 to connect to samba service, whereas in logging samba prefix is used.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Adding permanent firewalld rule<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now reload firewalld<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">firewall-cmd --reload<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong>&nbsp;firewalld service must be runnig for above procedure. To start firewalld use systemd command i.e&nbsp;<code>systemctl start firewalld.service<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to connect to Samba Server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Windows :<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Windows Operatig System, open the run by pressing in combination of&nbsp;<code>Start key + r<\/code>. Then type in this format&nbsp;<code>\\\\ip-address-of-samba-server\\shared-Direcory-name<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\\\\192.168.56.102\\sharedrepo<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Give username and password when it will ask.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Linux :<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">smbclient must be installed on system .<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(A) List the shared files or directory available in samba server<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">smbclient -L \\\\192.168.56.102 -U test <br><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In above command,<br>-L = For listing shared objects.<br>Samba Server IP Address = 192.168.56.102<br>User Name = test<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Below given is sample output<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sharad@linuxworld:~$ smbclient -L \\\\192.168.56.102 -U test\nEnter test's password: \nDomain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]\n\n\tSharename       Type      Comment\n\t---------       ----      -------\n\tIPC$            IPC       IPC Service (Samba Server Version 4.1.1)\n\tsharedrepo      Disk      shared-directory\n\ttest            Disk      Home Directories\nDomain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]\n\n\tServer               Comment\n\t---------            -------\n\tLOCALHOST            Samba Server Version 4.1.1\n\n\tWorkgroup            Master\n\t---------            -------\n\tMYGROUP              LOCALHOST\nsharad@linuxworld:~$<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(B) Access using smb console<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">smbclient \/\/192.168.56.102\/sharedrepo -U test<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After login, you will get smb console. You can use get and put command for getting\/putting the file. There are other commands you can use also.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sample output<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sharad@linuxworld:~$ smbclient \/\/192.168.56.102\/sharedrepo -U test\nEnter test's password: \nDomain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]\nsmb: \\&gt; \nsmb: \\&gt; help\n?              allinfo        altname        archive        backup         \nblocksize      cancel         case_sensitive cd             chmod          \nchown          close          del            dir            du             \necho           exit           get            getfacl        geteas         \nhardlink       help           history        iosize         lcd            \nlink           lock           lowercase      ls             l              \nmask           md             mget           mkdir          more           \nmput           newer          notify         open           posix          \nposix_encrypt  posix_open     posix_mkdir    posix_rmdir    posix_unlink   \nprint          prompt         put            pwd            q              \nqueue          quit           readlink       rd             recurse        \nreget          rename         reput          rm             rmdir          \nshowacls       setea          setmode        stat           symlink        \ntar            tarmode        timeout        translate      unlock         \nvolume         vuid           wdel           logon          listconnect    \nshowconnect    tcon           tdis           tid            logoff         \n..             !              \nsmb: \\&gt; <br><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(C) Mount the samba shared directory<br>Mount the samba shared directory in machine , your system must support cifs file system<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mount -t cifs \/\/192.168.56.102\/sharedrepo -o username=test \/mnt\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">QUELLE\/SOURCE:&nbsp;<a href=\"http:\/\/sharadchhetri.com\/2014\/10\/09\/centos-7-rhel-7-install-and-setup-samba-server-file-sharing\/\">http:\/\/sharadchhetri.com\/2014\/10\/09\/centos-7-rhel-7-install-and-setup-samba-server-file-sharing\/<\/a>&nbsp;by&nbsp;<a href=\"http:\/\/sharadchhetri.com\/author\/admin\/\">sharad chhetri<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we will learn, how to install and setup samba server ( file sharing server ) on CentOS<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[3],"tags":[15,110,111,117,170,171],"class_list":["post-127","post","type-post","status-publish","format-standard","hentry","category-kb","tag-centos","tag-install-samba","tag-install-samba-on-centos-7","tag-linux","tag-samba-installation-centos","tag-samba-server"],"_links":{"self":[{"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=127"}],"version-history":[{"count":0,"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}