Samba Server Configuration on RHEL7/Centos7/Fedora22 Step-by-Step Config Guide

Accessing Network Storage with SMB

samba allow Linux system to share files and printers across a network connection. By using its SMB(server message block) protocol, you Linux box can appear in windows network neighborhood or my network places just like any other windows machine. You can share files this way, as well as printers.

Samba is an Implementation of a common Internet file system(CIFS, also know as SMB) protocol server that can be run on almost every variant of UNIX in existence. Microsoft clients will use this protocol to access files and printers located on your UNIX box just as if it were a native window server.

samba-windows

Outline of Samba server:

Package                   : Samba, samba-common, samba-client(For clients), cifs-utils
File system             :  CIFS (common Internet file system)
Configuration File : /etc/samba/smb.conf
Usage                       : Used for sharing files and directories in the network between different platforms, like Linux-windows.
Daemon                   :  smbd (It provides the file and printer sharing services.), nmbd (It provides the NetBIOS-to-IP-address name service)

My setup:

  • Samba server ip add. and hostname: 192.168.1.10 (server1).
  • samba client ip add. and hostname(Linux): 192.168.1.11 (Client1).
  • samba client ip add. and hostname(Window): 192.168.1.12(client3).

Configuration of samba server

There is few steps to implement the samba server.

1) Check and Install the Samba Package, if not installed.
#rpm -qa samba

[root@server1 ~]# rpm -qa samba
[root@server1 ~]#

Install the Package using yum.
#yum install samba samba-client samba-common cifs-utils -y

If you are not configured yum server, refer the link Configure the Yum Server in Centos7/RHEL7/Fedora22

[root@server1 ~]# yum install samba samba-client samba-common cifs-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package cifs-utils.x86_64 0:6.2-7.el7 will be installed


===============================================
Install  4 Packages (+11 Dependent packages)

Total download size: 7.6 M
Installed size: 24 M
Is this ok [y/d/N]: y

2) Adding a system users in group and make a Directory,which will be shared.

We adding a “sambagrp” group ( or you can use existing group.) in which two users are added (i.e anil, shilpa).

[root@server1 ~]# groupadd sambagrp
[root@server1 ~]# useradd anil
[root@server1 ~]# useradd shilpa
[root@server1 ~]# usermod -a -G sambagrp anil
[root@server1 ~]# usermod -a -G sambagrp shilpa

Make a directory.
#mkdir /Sambadir1   

[root@server1 ~]# mkdir /Sambadir1

Give access to the new directory and change the group.

[root@server1 ~]# chmod 0770 /Sambadir1
[root@server1 ~]# chgrp sambagrp /Sambadir1

If your selinux is enabled, Change the sebooleum parameter as shown below,

[root@server1 ~]# setsebool -P samba_export_all_ro=1 samba_export_all_rw=1
[root@server1 ~]#

Change the context of the directory and change it according to samba.

[root@server1 ~]# semanage fcontext -a -t  samba_share_t "/Sambadir1(/.*)?"
[root@server1 ~]# restorecon -R -v /Sambadir1
restorecon reset /Sambadir1 context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:samba_share_t:s0
[root@server1 ~]#

Note: If you faced  “semanage: command not found” error.Then install the policycoreutils-python packages using yum install policycoreutils-python -y

3) Add the samba service to the firewall.

[root@server1 ~]# firewall-cmd --permanent --add-service=samba
success
[root@server1 ~]# firewall-cmd --reload
success
[root@server1 ~]#

4) Go to configuration file (i.e /etc/samba/smb.conf ) and make the following changes.

First take the backup smb.conf file.

[root@server1 ~]# cp -v /etc/samba/smb.conf /etc/samba/smb.conf.bak
‘/etc/samba/smb.conf’ -> ‘/etc/samba/smb.conf.bak’
[root@server1 ~]#

Edit the /etc/samba/smb.conf file.

#vim /etc/samba/smb.conf

[SambaGroup]
comment=Samba Shared
browsable=yes
path=/Sambadir1
writeable=yes
force group=sambagrp
valid users=@sambagrp
write list=@sambagrp
~
~
:wq

Note: For windows users, if your all systems in your network are using different WORKGROUP name edit the given below line in smb.conf with your workgroup name. Windows system by default uses the WORKGROUP as WORKGROUP. Try first without changing the WORKGROUP name,if required do the changes.

Check the syntax of the configuration file:

[root@server1 ~]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[SambaGroup]"
Loaded services file OK.
Server role: ROLE_STANDALONE

4) Create a user or use any existing user.

Create a new user or use any exiting user who will be allowed to log in as samba user, add that user to samba user.
As we have existed user “anil” and “shilpa”, let’s just make it samba user.

[root@server1 ~]# smbpasswd -a anil
New SMB password:
Retype new SMB password:
Added user anil.
[root@server1 ~]# smbpasswd -a shilpa
New SMB password:
Retype new SMB password:
Added user shilpa.
[root@server1 ~]#

Note: To delete the samba user use #smbpasswd -x <user name>

To check the all samba users

#pdbedit -L

[root@server1 ~]# pdbedit -L
anil:1012:
gaurav:1000:gaurav
shilpa:1013:
[root@server1 ~]#

6) Start and enable the samba services.

Note: “enable” option is used to Activate the Samba services at boot.

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

Now make sure the share is actually available to network clients:

[root@server1 ~]# smbclient -L //192.168.1.10 -U anil
Enter user1's password: 
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Sharename       Type      Comment
    ---------       ----      -------
    SambaGroup      Disk      Samba Shared
    IPC$            IPC       IPC Service (Samba Server Version 4.2.3)
    user1           Disk      Home Directories
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

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

    Workgroup            Master
    ---------            -------

How to connect window client with samba server

1) Connect from window to the samba server.

To connect from window to samba server, right click on “My computer” icon and select “Map network drive” option.

samba1

Specify the samba drive address as //192.168.1.10/SambaGroup, and press finish button, refer above image.

3) How to connect to Samba Server from client.

Now, Enter your samba server credentials for login and press “ok” button.

samba2

4) After mounting Create a some files.

samba5 

 

How to connect Linux client with samba server

1) Make sure the samba client is installed on client machine.

# rpm -qa samba*

[root@client1 ~]# rpm -qa samba
samba-4.2.3-10.el7.x86_64
[root@client1 ~]# rpm -qa samba*
samba-common-tools-4.2.3-10.el7.x86_64
samba-common-libs-4.2.3-10.el7.x86_64
samba-client-4.2.3-10.el7.x86_64
samba-libs-4.2.3-10.el7.x86_64
samba-common-4.2.3-10.el7.noarch
samba-client-libs-4.2.3-10.el7.x86_64
samba-4.2.3-10.el7.x86_64
[root@client1 ~]#

If samba is not Installed then install using below command.

[root@client1 ~]# yum install samba samba-client samba-common cifs-utils -y

2) Make sure the Samba share is accessible from this client.

[root@client1 ~]# smbclient -L //192.168.1.10/SambaGroup -U anil
Enter user1's password: 
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Sharename       Type      Comment
    ---------       ----      -------
    SambaGroup      Disk      Samba Shared
    IPC$            IPC       IPC Service (Samba Server Version 4.2.3)
    user1           Disk      Home Directories
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

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

    Workgroup            Master
    ---------            -------

3) Mount the samba drive.

First make the mount directory and mount the samba drive on client machine, refer below commands.

[root@client1 ~]# mkdir /mnt/sambashareddir
[root@client1 ~]# mount -o username=anil //192.168.1.10/SambaGroup  /mnt/sambashareddir  
Password for anil@//192.168.1.11/SambaGroup:*****
[root@client1 ~]# df -h  /mnt/sambashareddir/
Filesystem                 Size  Used Avail Use% Mounted on
//192.168.1.11/SambaGroup  6.7G  994M  5.7G  15% /mnt/sambashareddir
[root@client1 ~]#

To make permanent mount of “/mnt/sambashareddir” directory edit “/etc/fstab” file as follows.

# vim /etc/fstab

//192.168.1.11/SambaGroup     /mnt/sambashareddir    cifs   credentials=/root/.smbcredentials,defaults    0 0

~
~
:wq

Create a hidden file (i.e /root/.smbcredentials) and edit that file with your samba username and password.

# vim /root/.smbcredentials

username=anil
password=anil

~
~
:wq

Note: Change the permissions and ownership of /root/.smbcredentials file and set to 600 and root:root,respectively.

[root@client1 ~]# chmod 600 /root/.smbcredentials ; chown root:root /root/.smbcredentials 
[root@client1 ~]# ll /root/.smbcredentials 
-rw-------. 1 root root 30 Oct  7 02:46 /root/.smbcredentials
[root@client1 ~]#

Go to mount point and Lets see to add some files.

[root@client1 ~]# cd /mnt/sambashareddir/
[root@client1 sambashareddir]# touch file{1..5}
[root@client1 sambashareddir]# ls
file1  file2  file3  file4  file5
[root@client1 sambashareddir]#

 

Leave a Reply

1 Comment on "Samba Server Configuration on RHEL7/Centos7/Fedora22 Step-by-Step Config Guide"

Notify of
avatar
Sort by:   newest | oldest | most voted
Sudhir Kushwah
Guest

very nice

wpDiscuz