Sunday 20 October 2019

How to install and configure Samba Server on CentOS 7



Samba Server is an open source file sharing server. It allows to access files, folders and printers between Linux server and windows client.
This article describes How to install and configure Samba Server on CentOS 7.

Step 1. Package installation: Run the following command to install packages for Samba Server:

[root@linuxcnf ~]# yum install samba samba-client
Loaded plugins: fastestmirror
………………………..
Installed:
  samba.x86_64 0:4.9.1-6.el7                                                      samba-client.x86_64 0:4.9.1-6.el7

Dependency Installed:
  avahi-libs.x86_64 0:0.6.31-19.el7         cups-libs.x86_64 1:1.6.3-40.el7
……………………………
  samba-common-libs.x86_64 0:4.9.1-6.el7    samba-common-tools.x86_64 0:4.9.1-6.el7    samba-libs.x86_64 0:4.9.1-6.el7

Complete!
[root@linuxcnf ~]#
 
Step 2. Server Configuration: Create a folder and change permission as given below. Add a 
user to access secure Samba Server and set SMB password:
 
[root@linuxcnf ~]# mkdir -p /home/SambaShare
[root@linuxcnf ~]# groupadd smbgroup
[root@linuxcnf ~]# useradd –M –s /sbin/nologin –G smbgroup linuxcnf
[root@linuxcnf ~]# smbpasswd -a linuxcnf
New SMB password:
Retype new SMB password:
Added user linuxcnf.
[root@linuxcnf ~]#
[root@linuxcnf ~]# chmod -R 0775 /home/SambaShare
[root@linuxcnf ~]# chown -R linuxcnf.smbgroup /home/SambaShare
 
Modify the samba configuration and add the below contents in the configuration file. Comment
default share sections if not required.


[root@linuxcnf ~]# vi /etc/samba/smb.conf
…………………………………
[SambaShare] 
comment = Samba File Server Share 
path = /home/SambaShare 
valid users = @smbgroup 
guest ok = no 
writable = yes 
read only = no 
browsable = yes
 
Create a firewall rule to access Samba Services:
 
[root@linuxcnf ~]# firewall-cmd --permanent --add-service=samba
success
[root@linuxcnf ~]# firewall-cmd --reload
success
[root@linuxcnf ~]#
 
Step 3. Start and Enable Services: Run the following to start Samba services and enable on bootup:

[root@linuxcnf ~]# systemctl start smb
[root@linuxcnf ~]# systemctl start nmb
[root@linuxcnf ~]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
[root@linuxcnf ~]# systemctl enable nmb
Created symlink from /etc/systemd/system/multi-user.target.wants/nmb.service to /usr/lib/systemd/system/nmb.service.
[root@linuxcnf ~]#


Step 4. Validation: Browse the server IP address <\\192.168.43.23> on any file browser and the 
following credentials window will open. Enter earlier created credentials to access the Samba 
Shared folder on windows.

[root@linuxcnf ~]# smbclient -L localhost -U linuxcnf
Enter SAMBA\linuxcnf's password:

        Sharename       Type      Comment
        ---------       ----      -------
        SambaShare      Disk      Samba File Server Share
        IPC$            IPC       IPC Service (Samba 4.9.1)
Reconnecting with SMB1 for workgroup listing.

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------
        SAMBA                LINUXCNF
[root@linuxcnf ~]#


Done!!! Samba share is now accessible.

No comments:

Post a Comment