How to Mount Windows Share on Linux using CIFS



How to Mount Windows Share on Linux using CIFS

In this article, we will perform steps on How we can mount the Windows Shared folder on Linux Server using CIFS rpm or use smbclient command to get (for download) or put (for upload) files between Windows and Linux Server.

Please note we will be using OEL (Oracle Enterprise Linux) 7.9 & yum and wget command line utility and it requires internet access on your Linux Server.

[root@test-machine01 winshare]# cat /etc/oracle-release
Oracle Linux Server release 7.9

Verify if you already have cifs-utils and samba-client rpm installed in your Linux Server using the below commands.

[root@test-machine01 samba]# rpm -qa |grep cifs-utils
[root@test-machine01 samba]# rpm -qa |grep smbclient

If the above commands return no results that means no rpm is installed on the machine. Here we are using yum command to install required rpm packages since we have an internet enabled.

[root@test-machine01 samba]# yum install cifs-utils*
Dependencies Resolved

 Package                                       Arch                                      Version                                          Repository                                     Size
 cifs-utils                                    x86_64                                    6.2-10.el7                                       ol7_latest                                     84 k

  cifs-utils.x86_64 0:6.2-10.el7

[root@test-machine01 samba]#

[root@test-machine01 samba]# rpm -qa |grep cifs

[root@test-machine01 samba]# yum install samba-client*
Dependencies Resolved

 Package                                        Arch                                     Version                                           Repository                                    Size
 samba-client                                   x86_64                                   4.10.16-9.el7_9                                   ol7_latest                                   645 k
Installing for dependencies:
 libarchive                                     x86_64                                   3.1.2-14.el7_7                                    ol7_latest                                   319 k
 libsmbclient                                   x86_64                                   4.10.16-9.el7_9                                   ol7_latest                                   144 k

Transaction Summary
Install  1 Package (+2 Dependent packages)
  samba-client.x86_64 0:4.10.16-9.el7_9

Dependency Installed:
  libarchive.x86_64 0:3.1.2-14.el7_7                                                           libsmbclient.x86_64 0:4.10.16-9.el7_9


[root@test-machine01 samba]# rpm -qa |grep samba-client

Suppose on Windows Server we have Shared Folder by name of Test_Share. Same shared folder, we need to mount on our Linux Server, here we have already provided userid jkhan read-write access on this shared folder. Refer to below images.

As shown in the above images, the Window Shared folder is visible from Linux Server using smbclient command, Please replace IP as your Windows Server’s IP and then enter Windows Server’s password when prompted.

[root@test-machine01 winshare]# smbclient -L //192.168.XXX.XXX -U jkhan
Enter WORKGROUP\jkhan's password:

        Sharename       Type      Comment
        ---------       ----      -------
        ADMIN$          Disk      Remote Admin
        C$              Disk      Default share
        D$              Disk      Default share
        E$              Disk      Default share
        IPC$            IPC       Remote IPC
        Test_Share      Disk
Reconnecting with SMB1 for workgroup listing.

Create winshare folder in the Linux Root directory and mount the Window Shared folder using the below mount -t cifs command, You need to replace the IP address same as your Windows Server’s IP and enter a password for your Windows Server’s userid.

[root@test-machine01 ~]# cd /
[root@test-machine01 /]# mkdir winshare
[root@test-machine01 /]# mount -t cifs -o username=jkhan //192.168.XXX.XXX/Test_Share /winshare
Password for jkhan@//192.168.XXX.XXX/Test_Share:  ********

[root@test-machine01 /]# df -h /winshare
Filesystem                    Size  Used Avail Use% Mounted on
//192.168.XXX.XXX/Test_Share  466G  404G   63G  87% /winshare
[root@test-machine01 /]#
[root@test-machine01 /]# ls -ld /winshare
drwxr-xr-x. 2 root root 0 Dec 27 15:05 /winshare

[root@test-machine01 /]# cd /winshare
[root@test-machine01 winshare]# ls -ltr
total 1
-rwxr-xr-x. 1 root root 21 Dec 27 14:59 Test_File1.txt
drwxr-xr-x. 2 root root  0 Dec 27 15:11 Test_Dir
-rwxr-xr-x. 1 root root 58 Dec 27 15:14 Test_File2.txt
[root@test-machine01 winshare]#

Below are the same files exist in Windows Shared Folder.

Alternatively to mount you can use smbclient commands to get (download file from Windows to Linux Server) & put (upload file from Linux to Windows Server) files between Linux and Windows server. Follow the below command, in smb command prompt, type help to get a full list of available options.

[root@test-machine01 ~]# smbclient  //192.168.XXX.XXX/Test_Share -U jkhan
Enter WORKGROUP\jkhan's password:
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Sun Dec 27 14:59:22 2020
  ..                                  D        0  Sun Dec 27 14:59:22 2020
  Test_file1.txt                      A       21  Sun Dec 27 14:59:30 2020

                122096383 blocks of size 4096. 16435054 blocks available

smb: \> pwd
Current directory is \\192.168.XXX.XXX\Test_Share\

smb: \> get Test_file1.txt
getting file \Test_file1.txt of size 21 as Test_file1.txt (10.3 KiloBytes/sec) (average 10.3 KiloBytes/sec)

[root@test-machine01 ~]# ls -ltr
total 8
-rw-------. 1 root root 1529 Nov  1 10:01 anaconda-ks.cfg
-rw-r--r--. 1 root root   21 Dec 27 15:00 Test_file1.txt
-rw-r--r--. 1 root root    0 Dec 27 15:06 Test_File5.txt
-rw-r--r--. 1 root root    0 Dec 27 15:06 Test_File6.txt

smb: \Test_Dir\> put Test_File5.txt
putting file Test_File5.txt as \Test_Dir\Test_File5.txt (0.0 kb/s) (average 0.0 kb/s)
smb: \Test_Dir\> put Test_File6.txt
putting file Test_File6.txt as \Test_Dir\Test_File6.txt (0.0 kb/s) (average 0.0 kb/s)
smb: \Test_Dir\>
smb: \Test_Dir\> ls Test_File*
  Test_File3.txt                      A       21  Sun Dec 27 14:59:30 2020
  Test_File4.txt                      A        0  Sun Dec 27 15:05:25 2020
  Test_File5.txt                      A        0  Sun Dec 27 15:10:57 2020
  Test_File6.txt                      A        0  Sun Dec 27 15:11:01 2020

This document is only for learning purpose and constantly validate withi
the LAB environment first before applying in the LIVE environment.

Hope so you like this article!
Please share your valuable feedback/comments/subscribe and follow us below, don’t forget to click on the bell icon to get the latest update:

Registration Link
Telegram Technical Group

Whatsapp Technical Group

Facebook Page
Linkedin Group
Linkedin Page

 141 total views,  2 views today

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *

19 − four =

Follow us on Social Media
Open chat
Contact us:

Greetings of the day! How can we help you?