Thursday, June 2, 2016

RHEL7 - How to install And configure Samba Server and Client


How to install And configure Samba Server on RHEL7/CentOS7

Samba:- Samba is open source software. It uses the TCP/IP protocol to share file and print services for clients (windows/linux and other OS) using smb/cifs (server message block and common internet file system) protocol.



Pre-requisite tasks
hosts info

samba server
hostname: sam.expanor.local
ip address: 192.168.10.120

samba client:
hostname: sama.expanor.local
ip address: 192.168.10.110
OS: RHEL6

hostname: suvi.expanor.local
ip address: 192.168.10.8
os: Win 7


1. On your windows machine, open dos windows and run the command below.

net config workstation

get the workstation info.

2. Add host to dns or on host file if you are using host name rather than ip address.

at dos prompt type

notepad C:\Windows\System32\drivers\etc\hosts

192.168.10.120   sama.expanor.local   sama

Note: you might not be able to save file here, you save first on desktop and copy the file and past it on etc directory.

3. Add following services in /etc/services files

# cat /etc/services | grep netbios

Note: You will see 137, 138 and 139 tcp/udp added to the file.


Installation and configuration steps

1. Software installation

# rpm -qa | grep samba
# yum list installed | grep samba

If not installed, installed the packages

# yum install -y samba* policycoreutils-python


2. Create a user/group to use for samba. Assign samba password to user
# groupadd shared
# useradd -g shared suvi
# smbpasswd -a suvi

Note: You don't have to assign os password for user.

3. Create a shared directory and change owner/permission
# mkdir /opt/shared
# chown -R suvi:shared /opt/shared
# chmod -R 777 /opt/shared

note: pay attention to ownership/permission

4. Change selinux security context
# ls -ldZ /opt/shared
# chcon -R -t samba_share_t /opt/shared
# semanage fcontext -a -t samba_share_t /opt/shared
# setseboot -P samba_enable_home_dirs on
# getsebool -a | grep samba_export

Note: you can use restorecon -R on some cases

5. Editing /etc/samba/smb.conf file
# cd /etc/samba; cp -p smb.conf smb.conf.06022016
# vi smb.conf

edit the following contents

search for interface and  host allow entry and make changes

interfaces = lo enp0s25 192.168.10.0/24
hosts allow = 127. 192.168.10.

even if you forgot to add interface entry, its still working...

search for workgroup and update the entry based on finding from windows machine.

workgroup = WORKGROUP

go to the bottom of the page and paste the following entry

[shared]
path = /opt/shared
comment = Samba Shared directory
browseable = yes
valid users = suvi, devi,kbhusal, @shared
writable = yes
create mode = 0777
directory mode = 0777


Note: Once you done with configuration change, save it and run testparm command to test the configuration


6. Now, start and enable samba service in order to load upon reboot.
# systemctl enable smb.service
# systemcrt enable nmb.service
# systemctl start smb.service
# systemctl start nmb.service

Note: if you hosts entry has wrong host/ip on server and client, you will have problem making it work.
It will fail to start nmb.service if you have wrong entry on smb.conf file.

7. Disable your firewall to test it. Life makes easy. Most of the work place, os firewall is not enabled. But if you like to enable, enjoy
# systemctl disable firewalld

# systemctl enable firewalld

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

8. Verify the share from the server
# smbclient -L localhost -U suvi

9. Now go to windows machine and open your windows explorer and type you samba server ip or hostname as follow on the address bar

\\192.168.10.120

it will ask you for username and password. Use the os user name and the smbpassword in order to login.

upon successful login, you will see your shared name

In my case, it will be shared.

double click on the share and create one file. save it and go to your samba server. You should be able to see the file you just created.

10. Go to your linux client and type the following command to see the share

# smbclient -L //192.168.10.120 -U suvi

# mkdir /opt/smbclient
# mount -t cifs //192.168.10.120/shared /opt/smbclient -o username=suvi

Note: you will be using shared name not the share directory after hostname/ip


11. To make it permanent, add entry to fstab


# cat /root/secretinfo
username=suvi
password=samapassword

# /opt/sambaclient
# vi /etc/fstab
//192.168.10.120/shared /opt/sambaclient cifs credentials=/root/secretinfo,defaults 0 0

wq!

12. Mount and verify it
# mount -a
[root@sama ~]# df -hP | grep samba
//192.168.10.120/shared   20G   16G  4.2G  80% /opt/sambaclient

[root@sama ~]# cat >/opt/sambaclient/sambafile.linux1
This file is created on host same

Now, login to your windows machine and check your share, You should be able to see the newly created content.
Also on your samba server machine, you should be able to see the file content

[root@sam samba]# cd /opt/shared
[root@sam shared]# ls
sambafile.linux1  test_file.log  test_file.log1.txt
[root@sam shared]# cat sambafile.linux1
This file is created on host same
[root@sam shared]#

No comments:

Post a Comment