How to configure Samba Server in Centos 7 , Redhat 7 - Linux tech Solutions

Share on :

How to configure Samba Server in Centos 7 , Redhat 7

Configure Samba Server,Samba server configuration

Samba is a free software re-implementation of the SMB/CIFS networking protocol, and was originally developed by Andrew Tridgell. Samba provides file and print services for various Microsoft Windows clients and can integrate with a Microsoft Windows Server domain, either as a Domain Controller (DC) or as a domain member. As of version 4, it supports Active Directory and Microsoft Windows NT domains.

Samba runs on most Unix, OpenVMS and Unix-like systems, such as Linux, Solaris, AIX and the BSD variants, including Apple's macOS Server, and macOS client (Mac OS X 10.2 and greater). Samba is standard on nearly all distributions of Linux and is commonly included as a basic system service on other Unix-based operating systems as well. Samba is released under the terms of the GNU General Public License. The name Samba comes from SMB (Server Message Block), the name of the standard protocol used by the Microsoft Windows network file system.

Server Side Configuration

1) Firstly install the packages samba, samba-common, samba-client package.

[email protected]  #  yum  install  samba  samba-common  samba-client  -y

Note:If you don't know how to configure yum server you can refer the link given below
href="">Yum Server

2) Now create Directories you want to share.

[email protected] # mkdir /public
[email protected] # mkdir /private

Here we have create two directories to share /public for public share and /private for specific users.

3) Now give full Permission on the directories.

[email protected] # chmod 777 /public
[email protected] # chmod 777 /private

4) Now Apply the selinux context on the shared directories.
The selinux context of samba is samba_share_t

[email protected] # semanage fcontext -a -t samba_share_t '/public(/.*)?'
[email protected] # semanage fcontext -a -t samba_share_t '/private(/.*)?'

5) Now we will restore the context on the shared directories.

[email protected] # restorecon -vvRF /public
[email protected] # restorecon -vvRF /private

6) Now move to the configuration file of samba.

[email protected] # vim /etc/samba/smb.conf

7) Now go to the last line by pressing (shift + g) togethere and you have to give the share name, path, public, browseable, valid users, read list, write list, comment to both the shares.

[samba-public]        # Share Name

comment=Public Samba Share
[samba-private]        # Share Name

valid users=user1,user2
write list=user1
read list=user2
comment=Private Samba Share

8) To check that the configuration is correct.
#testparm [Press enter two times to check]

9) Now create two users.

[email protected] # useradd user1
[email protected] # useradd user2

10) Now give smb password and it is mandatory to give the smb password.

[email protected] # smbpasswd -a user1
[email protected] # smbpasswd -a user2

11) Now start and enable the service of the samba.

[email protected] # systemctl start smb nmb
[email protected] # systemctl enable smb nmb

12) Now apply the firewall rule.

[email protected] # firewall-cmd --permanent --add-service=samba
[email protected] # firewall-cmd --reload

Now Our Server Side Configuration is Complete.

Client Side Configuration

1) Install two packages samba-client and cifs-utils.

[email protected] # yum install samba-client cifs-utils -y

2) Check the connnection between the server and client.
[email protected] #smbclient -L [Server IP]

[email protected] #smbclient -L

[Don't enter the root password just press enter]

3) Now we will mount the shared directories from the server Permanently:-
//[server ip/share name] /public cifs defaults,_netdev,guests 0 0
//[server ip/share name] /private cifs defaults,_netdev,creds=/etc/abc.txt 0 0

[email protected] #vim /etc/fstab
// /public cifs defaults,_netdev,guests 0 0
// /private cifs defaults,_netdev,creds=/etc/abc.txt 0 0

4) Now we will create a file and give user credentials to mount.

[email protected] #vim /etc/abc.txt

The Password in this file you have to give is smbpassword.

5) Change the permission of abc.txt file to 600 so others cant access the file.

[email protected] # chmod 600 /etc/abc.txt

6) Now create mounting directory.

[email protected] #mkdir /public
[email protected] #mkdir /private

7) Now mount and check the directory.

8) In the public Directory the any user can create and remove files or directories because the directory has full permission for all users.

9) Go to the mount directory and make any file.

[email protected] #cd /private
[email protected] #touch file [It will show the error permission denied because it uses the user credentials which is having read only permission]

10) Now umount the mount directory.

[email protected] #umount /private

11) Again go to the abc.txt file and change the credential to user2.

[email protected]  #vim  /etc/abc.txt

The smbpassword of user2.

12) Now again mount the directory.

[email protected]   # mount -a
[email protected]  #  mount

13) Go to the mount directory and create a file.

[email protected]  #  cd  /public
[email protected]  # touch  file2
[email protected]  #  ls
[email protected]  #  file

file created because here we have used the credentials of user2 who have read and write permission on the directory

The Video Below is step by step guide .

Share on :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *