Install and Configure Samba on RHEL and Centos 8

0
59

Samba is a file sharing software which is sued to shared files between same and different operating systems. Today, You will learn that how to install and configure Samba share on RHEL 8 and CentOS 8 between other Linux and Windows systems.

Installation of Samba

login to your server from root user.

Use below command to install samba with necessary packages.

dnf install samba samba-common samba-client -y

Before configurations, make sure Windows machine is in same workgroup.
open the cmd prompt in Windows machine and run the following command

> net config workstation

Samba Configuration

before configuration rename samba default configuration file /etc/samba/smb.conf as backup.

# mv /etc/samba/smb.conf /etc/samba/smb.conf.default

Samba Anonymous File Sharing

Now create a shared folder on the server where all files/folders will be stored and set appropriate permissions on it and allow SELINUX for the samba configuration.

Run below commands

mkdir -p /srv/samba/anonymous
chmod -R 0755 /srv/samba/anonymous
chown -R nobody:nobody /srv/samba/anonymous
chcon -t samba_share_t /srv/samba/anonymous

Now make following changes in new samba configuration file.

# vi /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = rhel8
security = user
map to guest = bad user
dns proxy = no

[Anonymous]
path = /srv/samba/anonymous
browsable =yes
writable = yes
guest ok = yes
read only = no

Run below commant to verify samba configurations

testparm

Start and Add Samba Services in firewall

Run below command to add samba service in firewall

firewall-cmd --permanent --add-service=samba
firewall-cmd --reload

start and enable samba services

systemctl start smb.service
systemctl enable smb.service
systemctl start nmb.service
systemctl enable nmb.service

Access Samba Share Path

Now open Run prompt by pressing win + r key on your keyboard then type \\rhel8 and press enter key.

You will see Anonymous folder like below

Now you can add files/folders in this folder to share with other users.

Create samba secure share 

Create a secured share on the server where only allowed user can login and set appropriate permissions on it and allow SELINUX for the samba configuration.

Create group for samba users

groupadd securedgroup

Create samba user with securedgroup

useradd demo -G securedgroup

Now create secure share folder for samba users and set necessary permissions.

mkdir -p /srv/samba/secured
chmod -R 0770 /srv/samba/secured
chcon -t samba_share_t /srv/samba/secured
chown -R root:securedgroup /srv/samba/secured/

Add user to samba database and set its password

smbpasswd -a demo


Now add following lines in samba configuration file.

vi /etc/samba/smb.conf
[secured]
path = /srv/samba/secured
valid users = @securedgroup
guest ok = no
writable = yes
browsable = yes

Then restart samba

systemctl restart smb.service

Now access secured share from Windows

Now you can access the RHEL 8 secured folder from windows, open Run prompt by pressing win + r key on your keyboard
Then type \\SAMBA-SERVER-IP and press enter key.

My samba server IP is 192.168.130.152 so i will use \\192.168.130.152

Now Click on secured folder and it will ask you to enter samba user login details to access the folder.

You will see secured folder like below, Now you can add files/folders in this folder to share with other samba users.

 

Mount and access Samba secure share from Linux

I am going to use Ubuntu to access RHEL 8 Samba secure share.
Login to Ubuntu, open terminal and run below command.

First install samba client

apt-get install samba-client -y

Now use below command to verify Samba Share is accessible.

smbclient --user=demo -L //192.168.130.152

Command Syntax:
smbclient –user=samba-username -L //Samba-Server-IP

Access/Mount Samba share

smbclient //192.168.130.152/secured -U demo

Command Syntax:
smbclient //Samba-Server-IP/share-name -U samba-username

That’s it you have accesses the samba shared from Windows and Linux successfully.

LEAVE A REPLY

Please enter your comment!
Please enter your name here