How to Install Samba Step by Step

Installation of Samba


[root@node1 ~]# yum install samba
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package samba.x86_64 0:4.8.3-4.el7 will be installed
--> Processing Dependency: samba-libs = 4.8.3-4.el7 for package: samba-4.8.3-4.e                                                                                        l7.x86_64
--> Processing Dependency: samba-common-tools = 4.8.3-4.el7 for package: samba-4                                                                                        .8.3-4.el7.x86_64
--> Processing Dependency: libxattr-tdb-samba4.so(SAMBA_4.8.3)(64bit) for packag                                                                                        e: samba-4.8.3-4.el7.x86_64
--> Processing Dependency: libxattr-tdb-samba4.so()(64bit) for package: samba-4.                                                                                        8.3-4.el7.x86_64
--> Running transaction check
---> Package samba-common-tools.x86_64 0:4.8.3-4.el7 will be installed
---> Package samba-libs.x86_64 0:4.8.3-4.el7 will be installed
--> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.1.9)(64bit) for                                                                                         package: samba-libs-4.8.3-4.el7.x86_64
--> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.1.6)(64bit) for                                                                                         package: samba-libs-4.8.3-4.el7.x86_64
--> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.0.6)(64bit) for                                                                                         package: samba-libs-4.8.3-4.el7.x86_64
--> Processing Dependency: libpytalloc-util.so.2()(64bit) for package: samba-lib                                                                                        s-4.8.3-4.el7.x86_64
--> Running transaction check
---> Package pytalloc.x86_64 0:2.1.13-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                   Arch          Version             Repository    Size
================================================================================
Installing:
 samba                     x86_64        4.8.3-4.el7         node1        680 k
Installing for dependencies:
 pytalloc                  x86_64        2.1.13-1.el7        node1         17 k
 samba-common-tools        x86_64        4.8.3-4.el7         node1        448 k
 samba-libs                x86_64        4.8.3-4.el7         node1        276 k

Transaction Summary
================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 1.4 M
Installed size: 3.7 M
Is this ok [y/d/N]: y
Downloading packages:
--------------------------------------------------------------------------------
Total                                               14 MB/s | 1.4 MB  00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pytalloc-2.1.13-1.el7.x86_64                                 1/4
  Installing : samba-libs-4.8.3-4.el7.x86_64                                2/4
  Installing : samba-common-tools-4.8.3-4.el7.x86_64                        3/4
  Installing : samba-4.8.3-4.el7.x86_64                                     4/4
  Verifying  : pytalloc-2.1.13-1.el7.x86_64                                 1/4
  Verifying  : samba-4.8.3-4.el7.x86_64                                     2/4
  Verifying  : samba-common-tools-4.8.3-4.el7.x86_64                        3/4
  Verifying  : samba-libs-4.8.3-4.el7.x86_64                                4/4

Installed:
  samba.x86_64 0:4.8.3-4.el7

Dependency Installed:
  pytalloc.x86_64 0:2.1.13-1.el7     samba-common-tools.x86_64 0:4.8.3-4.el7
  samba-libs.x86_64 0:4.8.3-4.el7

Complete!


Verify SAMBA installation


By entering the following command, you can verify that the Samba has successfully installed and running. It will show the status of the Samba service.

[root@node1 ~]# systemctl start smb nmb
[root@node1 ~]# systemctl status smb
● smb.service - Samba SMB Daemon
   Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset:                                                                                         disabled)
   Active: active (running) since Mon 2019-11-04 18:27:16 +06; 31s ago
     Docs: man:smbd(8)
           man:samba(7)
           man:smb.conf(5)
 Main PID: 9347 (smbd)
   Status: "smbd: ready to serve connections..."
    Tasks: 4
   CGroup: /system.slice/smb.service
           9347 /usr/sbin/smbd --foreground --no-process-group
           9350 /usr/sbin/smbd --foreground --no-process-group
           9351 /usr/sbin/smbd --foreground --no-process-group
           └─9352 /usr/sbin/smbd --foreground --no-process-group

Nov 04 18:27:11 node1 systemd[1]: Starting Samba SMB Daemon...
Nov 04 18:27:16 node1 smbd[9347]: [2019/11/04 18:27:16.920332,  0] ../lib/u...y)
Nov 04 18:27:16 node1 systemd[1]: Started Samba SMB Daemon.
Nov 04 18:27:16 node1 smbd[9347]:   daemon_ready: STATUS=daemon 'smbd' fini...ns
Hint: Some lines were ellipsized, use -l to show in full.

[root@node1 ~]# systemctl status nmb
● nmb.service - Samba NMB Daemon
   Loaded: loaded (/usr/lib/systemd/system/nmb.service; disabled; vendor preset:                                                                                         disabled)
   Active: active (running) since Mon 2019-11-04 18:27:12 +06; 39s ago
     Docs: man:nmbd(8)
           man:samba(7)
           man:smb.conf(5)
 Main PID: 9348 (nmbd)
   Status: "nmbd: ready to serve connections..."
    Tasks: 1
   CGroup: /system.slice/nmb.service
           └─9348 /usr/sbin/nmbd --foreground --no-process-group

Nov 04 18:27:46 node1 nmbd[9348]: [1B blob data]
Nov 04 18:27:46 node1 nmbd[9348]:   Samba name server NODE1 is now a local ...11
Nov 04 18:27:46 node1 nmbd[9348]: [1B blob data]
Nov 04 18:27:46 node1 nmbd[9348]:   *****
Nov 04 18:27:46 node1 nmbd[9348]: [2019/11/04 18:27:46.030175,  0] ../sourc...2)
Nov 04 18:27:46 node1 nmbd[9348]:   *****
Nov 04 18:27:46 node1 nmbd[9348]: [1B blob data]
Nov 04 18:27:46 node1 nmbd[9348]:   Samba name server NODE1 is now a local ....1
Nov 04 18:27:46 node1 nmbd[9348]: [1B blob data]
Nov 04 18:27:46 node1 nmbd[9348]:   *****
Hint: Some lines were ellipsized, use -l to show in full.

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


Configuration firewall for Samba


[root@node1 ~]# firewall-cmd --permanent --add-service=samba
success
[root@node1 ~]# firewall-cmd --reload
success
[root@node1 ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: ssh dhcpv6-client samba
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

Configuration of Samba


1. First, we need to create a Samba directory, where all the shared data will be stored.

[root@node1 ~]# mkdir /sambadir
[root@node1 ~]# ls -ldZ /sambadir/
drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /sambadir/
[root@node1 ~]# semanage fcontext -a -t samba_share_t "/sambadir(/.*)?"
[root@node1 ~]# restorecon -Rv /sambadir/
[root@node1 ~]# ls -ldZ /sambadir/
drwxr-xr-x. root root unconfined_u:object_r:samba_share_t:s0 /sambadir/
[root@node1 ~]#

2. Make a backup of the configuration file by copying it in the same or another directory.
[root@node1 ~]# cp /etc/samba/
lmhosts           smb.conf          smb.conf.example
[root@node1 ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.back

Setting up Samba User Account


[root@node1 /]# useradd node2
[root@node1 /]# smbpasswd -a node2
New SMB password:
Retype new SMB password:
Added user node2.

Configuring Samba Shares


Now we will configure the directory samba as a share that we have created. For this, we will have to add the following lines in the Samba configuration file.
Add the following line to the bottom of the smb.conf file.

[root@node1 ~]#vi /etc/samba/smb.conf
[samba_share_t]
comment = Sambadir share
path = /sambadir
read only = no
browsable = yes


Restart Samba Service


[root@node1 ~]# systemctl restart smb


Connecting Samba Share


Connecting from Linux
There are two ways to connect Samba share from Linux client.
1. Using Command Line
2. Using GUI

1. Using the command line
To connect Samba share through the Linux command line, we need a smbclient tool. We need to install smbclient tool to the server
[root@node1 ~]# yum install samba-client

Once the installation is completed, run the command by using the following syntax to access Samba share
[root@node2 ~]# smbclient //node1/samba_share_t -U node2
Enter SAMBA\node2's password:
Try "help" to get a list of possible commands.
smb: \>

2. Using GUI
To access Samba share via GUI, open Linux File Manager. Click on Connect to Server and write down the below command.
smbclient //node1/samba_share_t

Comments

Popular Posts