TechJunkie is a BOX20 Media Company

Home PC Windows How to Automatically Mount Network Shares on Linux

How to Automatically Mount Network Shares on Linux

How to Automatically Mount Network Shares on Linux

A lot of tasks on Linux are complicated, especially when you have to do them manually. Mounting network shares is no different as you need to configure logins, input IP addresses, and more.

Everything goes much smoother when you automatically mount network shares. You can do that inside the fstab file. Read on and you will find out the best ways to mount Samba/CIFS and NFS shares automatically.

Make a Backup of the Fstab File

Before you begin, it is recommended to back up the fstab file because it is potentially very dangerous. You can mess up your entire system if you do something wrong while changing this file. Follow these steps to make backup the fstab file:

  1. Create a folder for the fstab backup. Also, maybe save the backup to a flash drive or an online cloud too, just to be sure. Use the following command:
    mkdir ~/system-backups
  2. Use sudo –s to get a root shell, and go to the /etc/ folder.
    cd /etc/
  3. Backup your file and store it in the folder you created. Use the following command.
    Cp fstab /home/username/system-backups
  4. Make sure to rename the backup file and give it a .bak extension.
    mv fstab fstab.bak

Restore the Fstab Backup File

how to automatically mount network shares

Here are the steps for restoring the backup:

  1. First, you need to use sudo –s to get a root shell.
  2. Next, you have to go to the /etc/ folder and delete the fstab file which is broken.
    cd /etc/rm fstab
  3. Now you need to copy your backup file back to the /etc/ directory.
    cp /home/username/system-backups/fstab /etc/
  4. Finally, change the name of the backup file.
    mv fstab.bak fstab

Automatically Mount NFS Share

Most novice users will find manual NFS mounting very difficult. Luckily, you can get automatic access to shares if you add a line to the fstab file. Follow these steps to do it:

  1. Locate the share you would like to mount.
    showmount –e 192.168.1.150
  2. Create a directory where the share would mount.
    mkdir ~/Network-files
  3. Access the fstab file using nano.
    sudo –snano /etc/fstab
  4. Type in the command for the mount. Here’s how it needs to look like:
    servername: /data /home/username/Network-Files nfs rsize=8192, timeo=14, _netdev 0 0

Make sure to replace the “data” section with the title of your NFS share. To make sure the alterations to /etc/fstab are saved, press together CTRL and O keys on your keyboard. Finally, reboot the computer. When you log in, the NFS share should mount automatically.

Automatically Mount Samba Share

SAMBA is also very hard and tedious to use. However, it is very useful because it can serve shared files to the Windows, Mac, and Linux, as well as iOS and Android operating systems.

First things first, you need to install the CIFS utilities. CIFS is a toolkit that makes sure the automatic mounting of the Samba shares goes smoothly.

Here are the commands you can use to install CIFS on different Linux managers:

Ubuntu

sudo apt install cifs-utils

Debian

sudo apt-get install cifs-utils

Fedora

sudo dnf install cifs-utils

Arch Linux

sudo pacman –S cifs-utils

OpenSUSE

sudo zypper install cifs-utils

Next, find and install CIFS utils. Now you can make a mount folder for SMB shares.

sudo mkdir /mnt/samba

Once you have downloaded the tools, you can finally set up your SMB mount with these commands:

sudo –s

nano /etc/fstab

Type the mount line.

//SERVER/share /mnt/samba cifs username=user,password=password 0 0

You should replace the “share” part with the actual name of the network share, and the “SERVER” part with your server’s name or its IP address. Also, instead of ”user” write your SAMBA username and instead of ”password” your actual SAMBA password.

When you type out the mount line, press together CTRL and O keys simultaneously to save all the changes. Finally, reboot the system and you will see SAMBA share mounted automatically when the system boots up.

linux

Automation Execution Completion

That is how you automatically mount network shares on Linux using SAMBA and NFS. If you follow the steps correctly and make this process automatic, it should save you a lot of time and effort.

Was this tutorial difficult to follow or you managed to do everything easily? Post in the comments if there is something you would like to add.

Do Snapchat Emojis Reset?

Read Next 

3 thoughts on “How to Automatically Mount Network Shares on Linux”

Daniel says:
I’ve got different users on Linux which will get different home-shares. How can I do this for them? The usernames and the shares can be defined in the fstab, or not?
Andre says:
very easy to follow and works perfectly. But the shares is read only, how to I change the command to make it read write for me?
kriba says:
Add the rw option in your /etc/fstab file.
Hervé S. says:
Interesting and very clear. Would this method lso apply with AFP volumes?
(on debian bullseye/sid here)
Thank you, and again, congratulations for the clarity!
H.

Leave a Reply

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


Kerry Bayley

Aug 20, 2019

My career as a project manager has given me plenty of time to get familiar with the full Microsoft suite, as well as a host of other tools, all of which I write about online.

1952 Articles Published

More