How to configure Samba Server in Centos 7 , Redhat 7 - Linux tech Solutions
How to configure Samba Server in Centos 7 , Redhat 7
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.
Note:If you don't know how to configure yum server you can refer the link given below
2) Now create Directories you want to share.
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.
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 '/private(/.*)?'
5) Now we will restore the context on the shared directories.
6) Now move to the configuration file of samba.
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.
comment=Public Samba Share
[samba-private] # Share Name
comment=Private Samba Share
8) To check that the configuration is correct.
#testparm [Press enter two times to check]
9) Now create two users.
10) Now give smb password and it is mandatory to give the smb password.
11) Now start and enable the service of the samba.
12) Now apply the firewall rule.
[email protected] # firewall-cmd --reload
Now Our Server Side Configuration is Complete.
Client Side Configuration
1) Install two packages samba-client and cifs-utils.
2) Check the connnection between the server and client.
[email protected] #smbclient -L [Server IP]
[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
//172.25.1.30/samba-public /public cifs defaults,_netdev,guests 0 0
//172.25.1.30/samba-private /private cifs defaults,_netdev,creds=/etc/abc.txt 0 0
4) Now we will create a file and give user credentials to mount.
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.
6) Now create mounting directory.
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] #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.
11) Again go to the abc.txt file and change the credential to user2.
The smbpassword of user2.
12) Now again mount the directory.
13) Go to the mount directory and create a file.
[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 .