Mount a network shared drive on GNU/Linux | Tutorial


Mount a network shared drive on GNU/Linux | Tutorial

Overview

In this post we will go through the process on how to mount a network shared drive on GNU/Linux. With this method, not only you can mount a network shared drive, you can also use this method to mount other network shared locations(network shared folders or other network shares). I have a network shared storage server, the server has HDDs in RAID configuration and the storage drives are shared over the network, I am going to use this setup as an example. Also in this post, we will cover the steps how to mount the network drives permanently and to mount automatically on boot.

UPDATE: published a post which covers another process how to setup a network share using NFS for Debian and Ubuntu based distros – LINK

There are couple of things we need to setup in order to make this configuration. We need to install an app called cifs-utils and we need to create a mount point. Also, for this to work – your network shared drive needs to be on a server with a static IP address.

Bellow you can find a video tutorial as well:

Creating a mount point

mount a network share on linux

First we need to create our mount point for our network share and for that we need to use the terminal. We will create the mount point in the /mnt folder. Start the terminal and use the following command:

sudo mkdir /mnt
sudo mkdir /mnt/share

Installing cifs-utils

Next what we need to do is to install the cifs-utils utility. This software will helps to mount and manage our network shares. Another reason we’re going to use this software is because this software supports other non-Linux partition extensions, such as partitions which Windows use.

To install the software, use the command:

For apt package manager(Debian and Ubuntu based distros):

sudo apt install cifs-utils

For RPM package manager(CentOS):

yum install cifs-utils

Mounting the network share

Now we can mount the network shared drive. First, please note, the commands bellow are an example and the parameters which are used are for my network setup. They will not be same as how is your network configured. You need to apply parameters according to your network settings.

First we use the command if credentials are set to the network share(meaning, the username and password is required to access the network share):

sudo mount.cifs //10.0.1.4/share /mnt/share/nmshare/ -o user=share,pass=share

Command description:

  • sudo mount.cifs – To mount the network share using cifs software and with root privileges.
  • //10.0.1.4/share – IP address and the name of the shared folder(this you need to change and to match your network settings)
  • /mnt/share/nmshare/ – The mount point we created earlier where our network share will be placed.
  • -o user=share,pass=share – Adding option to access the network share with credentials(adding username and password). Also, you can add option like this : -o username=share,password=share

If for your network share does not have credentials to access it, then you use the command to publicly mount the network share:

sudo mount.cifs //10.0.1.4/share /mnt/share/nmshare/

Mount permanently and automatically on boot

This method is optional and you do it if you want to.

!!!PLEASE PAY ATTENTION ON THIS STEP!!!

If you don’t do it properly, you could lock up your machine on the next restart. Fstab file is the boot process configuration file which has your HDD’s in it as well. So, if the file is not configured properly, you could prevent the machine from booting.

In order to make this configuration we need to access and edit the fstab config file. I kindly advise to backup the fstab config file first before making any changes to it. For this, we need to use the nano text editor and access the fstab file.

mount a network share on linux

Use the command:

sudo -s nano /etc/fstab

mount a network share on linux

You need to get a window like this. AT THE BOTTOM OF THE FILE add the following line(again the parameters needs to match your network settings):

//10.0.1.4/share /mnt/share/nmshare cifs username=share,password=share 0 0

This is an example if you have credentials set to access your network share. To mount the network share which does not have credentials, use this command:

//10.0.1.4/share /mnt/share/nmshare cifs guest,uid=1000 0 0

Once you finish with editing the file, save and exit.

Summary

This was the process how to mount a network shared drive on GNU/Linux using cifs-utils. Here we covered the process mounting the network shared drive for Debian / Ubuntu based distros and for CentOs as well. If this does not work out for you, there’s another way as well using the NFS tool. Link to that post is here.

Thank you very much for your time.


You may also like...

11 Responses

  1. Emanuel Acosta says:

    Thank you very much! I learned a lot with your guide. Keep up the good work!

    • MarkoNtech says:

      Hi Emanuel… Thank you so much for the feedback. Highly appreciated and I’m glad that the post was useful to you.

  2. LinuxN0ob says:

    when I type:
    sudo mount.cifs // /mnt/share/nmshare/ -o user=,pass=

    it says:
    mount error(112): Host is down
    Can somebody please explain what the problem is and how i can solve it?

  3. Yiannis says:

    Hi and thank you for your guide !! very helpful !!!
    I have the following issue after following your instructions

    sudo mount.cifs //10.0.x…../share /mnt/share/ -o user=corp.xxxxxxxxx.xx/administrator
    Password for corp.xxxxxxxxx.xx/[email protected]//10.0.x…../share: *********
    mount error: cifs filesystem not supported by the system
    mount error(19): No such device
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

    I use Linux on a chromebook GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)
    any ideas? the do not support cifs message respond to the linux or to the network share (windows server)?

  4. Kai says:

    Hi,
    thank you very much for this tutorial which helped me a lot even though I am a Linux rookie yet.

    There is one question though. I have done everything as you described and it works sofar that I can see whats on the mounted drive. But it seems that I only have reading rights and not for writing. Is there a way to change that?

    Thanks a lot.

    • MarkoNtech says:

      Hi Kai,
      Thanks for commenting and for the feedback. For the missing write permissions issue, there are several things to check and troubleshoot.
      Have you maybe tried to mount the shared folder using the last command on the bottom of the post(see the command bellow )
      sudo mount.cifs //10.0.1.4/share /mnt/share/nmshare cifs guest,uid=1000
      This command should grant you higher privileges and may allow write as well. Also, you can try with these:
      sudo mount.cifs //10.0.1.4/share /mnt/share/nmshare cifs guest,uid=1000,gid=1000
      or
      sudo mount.cifs //10.0.1.4/share /mnt/share/nmshare cifs guest,uid=1001,gid=1001
      Also, what’s worth checking is… If the folder you shared has the write permissions as well for any other user.
      (If the shared folder is from another Linux machine, the permission needs to have a value over 700, like 755 for an example – you can change this using the command:
      sudo chmod -R 755 /sharedfoldername
      But if it’s on a Windows machine, you need to check settings in the sharing properties and for an example again – in there for Everyone to have read/write permissions)

      Thanks again… hope this will help. If you need more assistance feel free to post again.

      Best regards…

  5. JoseKreif says:

    I added the line to fstab and my Raspberry Pi stopped booting. Had to restore the thing from scratch. What’s up with that?

  6. Antoine says:

    So everyone looking at fstab Will be able to steal your credential. Nice.

    You should make a crypted credential file and use it to auth for the network drive.

    The solution of this tutorial is unsecure and suboptimal.

  7. Antoine says:

    Also for all the people having an error there add “vers=1.0” at the end of the line after your credential.

Leave a Reply

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