This article we will be going through setting up SAMBA server with Window/Linux and Linux clients respectively. This article will definitely help you if you are called up for setting up file servers in enterprise environments where we will likely find different type of devices and operating systems .
Our current testing environment persist of 2 Centos 7 boxes and one Windows 10 machine.
SAMBA Server : 192.168.6.232
SAMBA Client (Linux) : 192.168.6.233
SAMBA Client (Windows) : 10.10.16.16
SERVER SIDE
INSTALL PACKAGE
Firstly , we will need to install the respective package in the server side .
# yum install samba samba-client -y
START THE SAMBA SERVICE
After installing the package we will need to start up the service as well as enable the service.
# systemctl start smb
# systemctl enable smb
FIREWALLD
After starting and enabling the service we will need to add the service in the firewall .
# firewall-cmd --add service samba --permanent
# firewall-cmd --reload
CONFIGURING SAMBA SHARE
We will need to create a folder which we want to share and also dive into the main configuration file /etc/samba/smb.conf. In this particular example we would like Harry to be given full permission where as the user Andrew to be given Read Only permission.
1. CREATE A DIRECTORY YOU WANT TO SHARE
# mkdir /local
2. CREATE MULTIPLE USER TO READ/WRITE
# useradd harry –s /sbin/nologin
# useradd andrew -s /sbin/nologin
3. ASSIGN SMBPASSWD TO THE USERS
# smbpasswd –a harry
New Smb Password:
Retype new Smb Password :
#smbpasswd -a andrew
New Smb Password:
Retype new Smb Password :
4. CHANGE SELINUX SECURITY CONTEXT TO THE SHARE DIRECTORY
We will either need to disable the selinux or set the correct security context for the file to be shared in proper way otherwise selinux will prevent user from accessing the share file.
# chcon –t samba_share_t /local
5. CHANGE THE MAIN CONFIGURATION FILE
[ ] = Share name
comment = Brief introduction about the share optional parameter
path = It specifies absolute path of the directory
browseable = If 'Yes' = visible share
If 'No' = Read-write enable share
writable = If 'no' = Read only share
If 'yes' = Read-write enable share
valid users = To allow access of the given shared directory to the specified users only
write list = To allow write privilege to the given user only
hosts deny = To deny access of the given folder to the specified host.
hosts allow = To allow access of shared directory from the specified host only.
create mask = To force files to be created with
#vim /etc/samba/smb.conf
[local]
comment = my local
path = /local
browseable = yes
write list = harry
hosts allow = 192.168.6. (Overall Network)
hosts deny = 192.168.6.20 (Single Host)
Note: In our example Write List is only given to Harry because the user Harry is only allowed to Read/Write where as for the user Andrew we will keep it as Read Only .
6. SET ACL (for the user Harry)
We have set ACL permission of rwx to the user harry for the folder (local) .
#setfacl -m u:harry:rwx /local
7. VERIFY THE FILE IS BEING SHARED
#smbclient -L localhost
OR
#testparm
CLIENT SIDE (LINUX)
INSTALL THE PACKAGE
1. You just need to install the samba-client package
# yum install samba-client
# yum install cifs-libs
2. Make sure that the folder you want to share is visible
# smbclient –L 192.168.6.232
3. Create file for storing the username and password for samba client
# vim /root/pass.txt
username=harry
password=redhat ( write the password which you kept in the server side) (No Space)
MOUNTING THE SAMBA SHARE IN LINUX
# vim /etc/fstab
//192.168.6.232/local /mnt cifs credentials=/root/pass.txt,sec=ntlmssp 0 0
CHECK THE FOLDER
We will need to first create user harry in our client end
# useradd harry
# passwd harry
New Password :
Retype new Password :
After we create a user then we will need to switch our user from root to user Harry
# su - harry
# cifscreds add 192.168.6.232
# cd /mnt
Then we can create a file inside /mnt which is the folder where we have mounted for our folder /local .
# touch file1
The file which we have recently created should have the user and group permission of the user Harry and our tasks finally gets completed .
CLIENT SIDE (WINDOWS)
The folder can also be shared in windows which we have already discussed about it earlier. In order to mount the folder in Windows PC go to MY PC and the choose Computer then map the network drive . After that we will need to assign a letter for the drive to be mapped check the box where it is written "Connect using different credentials". You can check the screenshot which I have captured below
We can create a file and check the permission for the created file in our linux server . The file permission should belong to user Harry.
CONCLUSION
In the above article we have discussed about how we can share folder in linux as well as windows platform using samba multiusers share. We have also learned about managing firewall, selinux as well as accessing the folder with an particular user .
Please, feel free to drop a comment using the form below if you have any comments or suggestions.
CONCLUSION
In the above article we have discussed about how we can share folder in linux as well as windows platform using samba multiusers share. We have also learned about managing firewall, selinux as well as accessing the folder with an particular user .
Please, feel free to drop a comment using the form below if you have any comments or suggestions.
Comments
Post a Comment