Hello and welcome to part 2 of  configuring samba.In our previous tutorial we discussed how to configure samba server and then accessed linux samba share from windows.  In this second part we will learn how to configure samba client on linux and will demonstrate how to access linux samba server from linux with samba client configured on it.


Assumption: We assume you have already configured samba server on linux as per instructions in our part 1 tutorial

Client side Linux

For using samba services  on Linux client machine you need to install it samba-client.

[root@faraz Faraz]# yum install samba-client –y

Here I am using CentOS 6.7 version of linux . So I need to start the service by using below command.

[root@faraz Faraz]# service smb start

To view/display the shared data use below command

Syntax smbclient –L ip-address-of –samba-server –U user-name

[Faraz@faraz ~]$ smbclient -L 192.168.56.101 -U xyz
Enter xyz's password:

Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

Sharename       Type      Comment
---------       ----      -------
Share.folder    Disk
IPC$            IPC       IPC Service (Samba Server Version 4.2.3)
xyz             Disk      Home Directories

There are two ways to access data.

  1. Smb Mode
  2. Mounting




Using smb mode you can access data in command line by define the path of shared folder with its source (IP). Syntax smbclient  //source-ip/dir-name  -U user-name

[Faraz@faraz ~]$ smbclient //192.168.56.101/share.folder -U xyz
Enter xyz's password:
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]
smb: \>

As you can see the mode of smb in above image now we can download and upload files by using below commads.

For downloading single file or multiple files with extension;

smb: \> get file-name #single file download
smb: \> mget file-name  # multiple file download

For uploading single file or multiple files with extension;

smb: \> put file-name # single file upload
smb: \> mput file-name #multiple file upload

You can check the current working directory by using command.

smb: \> pwd
Current directory is \\192.168.56.101\share.folder\
smb: \>

 

You can mount the shared folder by using mount command.

Syntax mount  -t cifs //source  /destination  -o username=user-name or mount.cifs //source  /destination  -o username=user-name

[root@faraz Faraz]# mount -t cifs //192.168.56.101/share.folder /home/Faraz/ -o username=XYZ
Password:
[root@faraz Faraz]#

For permanent mounting we have to define in the fstab file by using vi editor. Add the line in end of the file.

[root@faraz Faraz]# vi /etc/fstab

# Created by anaconda on Wed Dec 30 14:50:47 2015

# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_faraz-lv_root /                       ext4    defaults        1 1
UUID=8af0604c-7678-4f01-a386-d1a4735da749 /boot                   ext4    defaults        1 2
/dev/mapper/vg_faraz-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

//192.168.56.101/share.folder /mnt/smb cifs username=xyz,password=**** 0 0

You can also use these commands when data is  shared by windows-pc and you are accessing share  at linux side. In below image you will see the shared data from windows using Linux client CLI

[root@faraz fahmed]# smbclient -L //192.168.56.105 -U ideas
Enter ideas's password:

Domain=[FARAZAHMED-PC] OS=[Windows 7 Ultimate 7601 Service Pack 1] Server=[Windows 7 Ultimate 6.1]

Sharename       Type      Comment
---------       ----      -------
ADMIN$          Disk      Remote Admin
C$              Disk      Default share
Creative Ideas  Disk
HP LaserJet Professional P1102 Printer   HP LaserJet Professional P1102
I$              Disk      Default share
IPC$            IPC       Remote IPC
New folder      Disk
print$          Disk      Printer Drivers

As you can clearly see the domain name and windows version as well in top and shared printer and folders.

Commands are same for accessing data from Windows PC. It just like working on SFTP.

I hope you enjoyed this article/tutorial.In this tutorial we have learnt configuring linux samba client and accessed server using smd mode and mounting share . We have also learnt how to access shared folder on windows using linux samba client. Once again thanks for visiting our blog and please do let us know if you see any error in our blogs and feel free to suggest to improve our contents. See you in next tutorial

SUBSCRIBE OUR NEWSLETTER
I agree to have my personal information transfered to MailChimp ( more information )
Join us by subscribing to our newsletter and learn IT subjects for free
We hate spam. Your email address will not be sold or shared with anyone else.