Hamsa K
Editor
6 min read | 4 years ago

How to Install and Configure Samba in Centos 7

How to install and configure Samba in Centos /RHEL

It provides shared services for files and printers between different computers in a local area network.The SMB protocol is a client/server protocol through which clients can access shared file systems, printers, and other resources on the server. By setting “NetBIOS over TCP/IP”, Samba can not only share resources with LAN hosts, but also share resources with computers around the world.

Here i am using centos 7 system as server and windows 10 as client

Before you proceed to configure samba, make sure the Windows machine is in the same workgroup to be configured on the CentOS server.

There are two possible ways to view the Windows machine workgroup settings:

  • Right clicking on “This PC” or “My Computer” → Properties → Advanced system settings → Computer Name
  • Alternatively, open the cmd prompt and run the following command, then look for workstation domain” in the output as shown below
net config workstation

Step 1: Install samba server

[root@lampblogs ~]# yum install samba samba-client samba-common

Samba configuration file path /etc/samba/smb.conf, make a backup before modifying.

[root@lampblogs ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.orig

Then empty samba.conf by below command

[root@lampblogs ~]# cat /dev/null > /etc/samba/smb.conf
                    or
[root@lampblogs ~]# echo " " > /etc/samba/smb.conf

Step2 : configuring samba

[root@lampblogs ~]# vi /etc/samba/smb.conf

Enter the following to the configuration file smb.conf

[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = centos
security = user
map to guest = bad user
dns proxy = no
#============================ Share Definitions ============================== 
[Anonymous]
path = /srv/samba/anonymous
browsable =yes
writable = yes
guest ok = yes
read only = no
force user = nobody

This configuration will first create a directory anonymouse that anyone can read and write.

[root@lampblogs ~]# mkdir -p /srv/samba/anonymous
[root@lampblogs ~]# chmod -R 0775 /srv/samba/anonymous
[root@lampblogs ~]# chown -R nobody:nobody /srv/samba/anonymous

Finally, start and enable samba services to start automatically at next boot and also apply the above changes to take effect.

[root@lampblogs ~]# systemctl enable smb.service
[root@lampblogs ~]# systemctl enable nmb.service
[root@lampblogs ~]# systemctl restart smb.service
[root@lampblogs ~]# systemctl restart nmb.service

If selinux is enabled, enter the following command to allow SELinux to be used for samba configuration.

[root@lampblogs ~]# chcon -t samba_share_t /srv/samba/anonymous

Test on windows computer to confirm anonymous read and write.

Step 3: Setup secure file sharing

First start by creating a samba system group, then add users to the group and set a password for each user.

[root@lampblogs ~]# groupadd smbgrp
[root@lampblogs ~]# useradd lampblogs -G smbgrp
[root@lampblogs ~]# smbpasswd -a lampblogs

Then create a secure directory where the shared files will be kept and set the appropriate permissions on the directory with SELinux security context for the samba

[root@lampblogs ~]# mkdir -p /srv/samba/secure
[root@lampblogs ~]# chmod -R 0770 /srv/samba/secure
[root@lampblogs ~]# chown -R root:smbgrp /srv/samba/secure
[root@lampblogs ~]# chcon -t samba_share_t /srv/samba/secure

Then edit /etc/samba/smb.conf and add the following to the end of the file.

[secure]
path = /srv/samba/secure
valid users = @smbgrp
guest ok = no
writable = yes
browsable = yes

Restart Samba services to apply the changes.

[root@lampblogs ~]# systemctl restart smb.service
[root@lampblogs ~]# systemctl restart nmb.service

Test on windows computer, open secure will prompt for username and password

Now, goto any windows client system.ClickStart -> Run. Enter the samba server IP as shown below.

Double click to open the secure share. You’ll be asked to enter the user name and password to access the share.

 

and click on ok.Now you can access secure shared folder and samba server is ready to use on centos 7 server.

 



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy