CentOS / RHEL 7 : How to Install Samba Server

Samba server installation and configuration for Linux to Linux file transfer:-

1. Samba server is used SMB (server message Block ) and CIFS (common interface file server) protocols for file transfer over the network
2. Using the samba server we can sharing the directory or folder across the corporate network. Sharing the directories and files from linux to windows and windows to linux using with SMB protocol.
3. We can also use it for print server and printer sharing
4. Mount windows shares CIFS shares into linux server
5. samba is used NTLMSSP security for fully secured shared using user authentication

Samba server profile:-

Packages required:-samba samba-client and cifs-utils
Port number:- 445
Services:- smb for linux and nmb for windows Netbios name resolution
Configuration file:- /etc/samba/smb.conf
Samba installation and configuration steps for RHEL7.x
Configuration of /etc/hosts file entries into server1 and desktop1 and check both machines are communicates to each others:-

# vim /etc/hosts
192.168.72.11 server1.example.com server1
192.168.72.12 desktop1.example.com desktop1
Configuration into server side ( server1 ):-

Step:-1 -> install the below required packages for samba sharing
[root@server1 root]# yum install samba samba-client –y

Step:-2 -> create share directory and assign it to file permission and selinux permission for this directory is accessible by client machine
[root@server1 root]# mkdir /smbshare
[root@server1 root]# chmod 770 /smbshare
[root@server1 root]# groupadd -r ITusers
[root@server1 root]# semanage fcontext -a –t samba_share_t ‘/smbshare(/.*)?’
[root@server1 root]# restorecon –vvRF /smbshare
[root@server1 root]# ls -ldZ /smbshare

Step:-3 -> change the /etc/samba/smb.conf file with samba share name which is accessible by client
[root@server1 root]# vim /etc/samba/smb.conf
[ samba ]
Path = /smbshare
Writable = yes
Write list = @ITusers
Valid users = @ITusers

Step:-4 -> create samba users for access to this samba share directory using its credentials

[root@server1 root]# useradd -s /sbin/nologin -G ITusers samba
[root@server1 root]# smbpasswd -a samba
Type password:- redhat
Retype:- redhat
[root@server1 root]# useradd -s /sbin/nologin redhat
[root@server1 root]# smbpasswd -a redhat
Type password:- redhat
Retype:- redhat

Step:-5 -> start and enable smb and nmb services
[root@server1 root]# systemctl start smb nmb
[root@server1 root]# systemctl enable smb nmb

Step:-6 Add firewall rules to apply for samba server
[root@server1 root]# firewall-cmd --permanent --add-services= samba
[root@server1 root]# firewall-cmd --reload

Client side configuration for samba mount :-

[root@Desktop1 root]# yum install cifs-utils -y
[root@Desktop1 root]# mkdir /mnt/samba
[root@Desktop1 root]# mkdir /mnt/redhat
[root@Desktop1 root]# mount -O username=samba //server1/samba /mnt/samba
[root@Desktop1 root]# df -h
Check and verify that /mnt/samba directory is mounted
[root@Desktop1 root]# vim /mnt/samba/test1.txt
This is samba share directory
[root@Desktop1 root]# cat /mnt/samba/test1.txt

This is samba share directory
That’s show samba user is read and write permission on /mnt/samba directory because it is ITusers group member

[root@Desktop1 root]# mount -O username=redhat //server1/samba /mnt/redhat
[root@Desktop1 root]# df -h
/smbshare 276G 141G 121G 54% /mnt/redhat
[root@Desktop1 root]# vim /mnt/redhat/test2.txt
Permission denied to access
[root@Desktop1 root]# cat /mnt/samba/test1.txt
This is samba share directory
Samba multiusers mount configuration into client side (desktop1 ):-

[root@Desktop1 root]# yum install cifs-utils -y
[root@Desktop1 root]# mkdir /mnt/multiuser
[root@Desktop1 root]# useradd samba
[root@Desktop1 root]# useradd redhat
[root@Desktop1 root]# vim /root/multiuser.txt
Username=samba
Password=redhat

Mount share folder with permanent mount methods:-

[root@Desktop1 root]# vim /etc/fstab
//server1/samba /mnt/multiuser cifs credentials=/root/multiuser.txt,multiusers,sec=ntlmssp defaults 0 0
[root@Desktop1 root]# mount -a

[root@Desktop1 root]# df –h

/smbshare       276G       141G      121G      54%      /mnt/multiuser
Now login into our users and add servers credentials for access

[root@Desktop1 root]# su - samba
[root@Desktop1 root]$ vim /mnt/multiuser/test1.txt
Permission denied to access /mnt/multiuser directory
[samba@Desktop1 root]$ cifscreds add server1
[samba@Desktop1 root]$ vim /mnt/multiuser/test1.txt
This is samba share folder
[samba@Desktop1 root]$ cat /mnt/multiuser/test1.txt
This is samba share folder
[samba@Desktop1 root]$ exit
[root@Desktop1 root] # su – redhat
[redhat@Desktop1 root] $ cifscreds add server1
[redhat@Desktop1 root]$ vim /mnt/multiuser/test1.txt
Permission denied to access /mnt/multiuser directory

Into samba multiuser redhat user only read access to /smbshare directory while samba user is fully access to this directory
Samba server configuration for Linux to Windows file sharing:-

[root@server1 root]# yum install samba samba-client -y
[root@server1 root]# groupadd -r security
[root@server1 root]# mkdir /home/samba
[root@server1 root]# chmod 770 /home/samba
[root@server1 root]# chgrp security /home/samba
[root@server1 root]# semange fcontext –a –t samba_share_t ‘/home/samba(/.*)?’
[root@server1 root]# restorecon –vvRF /home/samba
Edit samba configuration file for linux samba share access through windows server

[root@server1 root]# vim /etc/samba/smb.conf

Change workgroup according our windows domain name:-
Workgroup = WORKGROUP or ABC.com - Domain name of win server 2012
hosts allow = 127. 192.168.72.
add follows entries to the end
[samba] - share name
Path = /home/samba
Writable = yes
Create mode = 0770
Directory mode = 0770
Valid users = @security

[root@server1 root]# useradd samba -G security samba
[root@server1 root]# smbpasswd –a samba
New smb passwd:-
Retype passwd:-
[root@server1 root]# systemctl start smb nmb
[root@server1 root]# systemctl enable smb nmb
[root@server1 root]# firewall-cmd --permanent –add-service=samba
[root@server1 root]# ]# firewall-cmd --reload


No comments:

Post a Comment

T he primary difference is that  Linux  and  Unix  are two different Operating Systems though they both have some common commands. Let...