Overview

In this post we will go through the process on how to mount a network shared drive on Linux. We are going to cover the methods with cifs-utils in order to mount the network shared drive with the SMB protocol and the NFS share as well, by using the nfs tools. Also in this post, we will cover the steps how to mount the network drives permanently and to mount automatically on boot.

To give you small heads up - the setup presented in this post to give you this demonstration is just one server that acts as the storage server and the Linux desktop client.

UPDATE: published posts that demonstrates another process - how to setup a network share using NFS for Debian and Ubuntu, Rocky Linux 8 and Alma Linux and host your own network shared storage - Alma Linux Rocky Linux 8, Ubuntu 20.04, Debian

Also, for this to work - your network shared drive needs to be on a server with a static IP address.

 Mount a network shared drive on Linux

Creating a mount point

First we need to create our mount point for our network share. We will create the mount point in the home dir of our user(this is just to make it the process a bit simpler), so that shared folder will look something like this - /home/username/mnt/share. Start the terminal and use the following command:

mkdir /mnt
mkdir /mnt/shared_folder

Mount a network shared drive on Linux

This is of course just for the example, you can change the name and location to your liking.

Installing the cifs-utils package

First we’ll be covering the process of mounting the network share that uses the SMB or the SAMBA protocol. What we need to do is to install the cifs-utils utility. This software will help us to mount and manage our network shares. To install the software, run these based on the package manager you have:

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

sudo apt install cifs-utils

For RPM package manager(CentOS/Fedora):

sudo dnf install cifs-utils

Mounting the network share with cift-utils

Now we can mount the network shared drive.

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 //192.168.124.235/my_share /home/markon/mnt/share/shared_folder -o user=markon,pass=markon1234

Mount a network shared drive on Linux

Command description:

  • sudo mount.cifs - To mount the network share using cifs software and with root privileges,
  • //192.168.124.235/my_share - IP address of the server that hosts the share and the name of the SAMBA share, name of the share is defined in the SAMBA server settings,
  • /home/markon/mnt/shared_folder - The mount point we created earlier where our network share will be placed.
  • -o user=markon,pass=markon1234 - Adding option to access the network share with credentials(adding username and password). Also, you can add option like this : -o username=markon,password=markon1234

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 //192.168.124.235/my_share /home/markon/mnt/share/shared_folder

IMPORTANT NOTE:

The sudo mount.cifs command will only mount the shared temporarily, only for the current running session and on the next reboot/shutdown the mount will not be there not will automatically mount on the next machine boot.

Another thing important to note is that - since we need to run the command with sudo, in the long run it will be a hassle to use the share as is, since the share will be claimed by the root user(because of sudo) and that is because of how the cifs-utils is installed(with sudo apt/dnf install command). It’s in-built the in the cifs-utils tool by default and you can try to mount the share without the sudo , but you’re probably going to get an error:

This program is not installed setuid root - “user” CIFS mounts not supported.

Luckily, there’s a workaround and to remedy this, we need to apply a new user permisison on the mount.cifs binary. Here’s how it’done. Run the following command as is:

sudo chmod u+s /sbin/mount.cifs

Mount a network shared drive on Linux

After this, the mount command without sudo should work:

mount.cifs //192.168.124.235/my_share /home/markon/mnt/share/shared_folder -o user=markon,pass=markon1234

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 or at least be extremely careful. For this, we need to use a text editor and access the fstab file.

Use the command:

sudo -s nano /etc/fstab
or
sudo vim /etc/fstab

Mount a network shared drive 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):

//192.168.124.235/my_share /home/markon/mnt/share/shared_folder -o cifs user,username=markon,password=markon1234 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:

//192.168.124.235/my_share /home/markon/mnt/share/shared_folder cifs guest,uid=1000 0 0

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

Testing the network share

Once we mounted the network share, we can try it out to make sure that it’s working as intended. Let’s first try to see if we can write to the share and create a file. Here i navigated to the /mnt/shared_folder under te home which i used for my mount point on my workstation and created an example file:

Mount a network shared drive on Linux

Now let’s if the file is present on the server and voila, it’s there alright:

Mount a network shared drive on Linux

I also created another test file on the actual server and to see if my workstation will detect the changes and it sure does:

Mount a network shared drive on Linux

Mount a network shared drive using the NFS client

NFS is nowadays reffered to as standard for managing network shares on Linux/Unix environments(my personal preference as well). Here i will again demonstrate again the client side of the network share mount process. If you need the entire setup with the network server, please refer to the one of the posts at the begining of this post where i left links to the in-depth posts for the NFS server/client setup for various Linux distro’s - POSTS

I will also demonstrate the simplest NFS config/setup just for demonstration purposes.

NFS runs on the server-client model, meaning in order to gain access, you to need to have NFS client installed. Install the NFS client:

sudo apt install nfs-common
or
sudo dnf install nfs-utils

The command to mount the NFS share should be like this(just to test if the mount works):

sudo mount 192.168.124.235:/home/markon/mnt/nfs-share /home/markon/mnt/nfs-share

To elaborate the command:

  • The mount will targer our NFS server - this part of the command 192.168.124.235:/home/markon/mnt/nfs-share and this is the IP adddress of the server along with the path of the shared folder created on the server.
  • Second part of the command is the path we designated to act as our mount point, this part - /home/markon/mnt/nfs-share

Here, sudo is necessary because the permisions of our user in the sudoers file needs to be adjusted in order to mount the point without the sudo. Example:

markon ALL=(ALL) NOPASSWD: /bin/mount, /bin/umount, /sbin/mount, /sbin/umount

Mount the NFS share permamently on boot

On your workstation, the fstab needs to be edited again and add the config for the NFS server mount point:

NOTE AGAIN

Add this config line again at the bottom of the fstab file.

192.168.124.235:/home/markon/mnt/nfs-share   /home/markon/mnt/nfs-share   nfs   rw,soft,noatime,x-gvfs-show

Mount a network shared drive on Linux

Testing the share access againg on the server:

Server: Mount a network shared drive on Linux

Workstation: Mount a network shared drive on Linux

Share also will be present on the file explorer:

Mount a network shared drive on Linux

Summary

This was the process how to mount a network shared drive on Linux using cifs-utils and NFS. Here we covered the process mounting the network shared drive with both cifs and nfs utilites and also covered how to mount the share permanently, in another how to mount the share automatically on boot. This process is test on Debian / Ubuntu based distros and CentOS/Fedora as well.

Thank you very much for your time…