1. Overview

Managing network drives is an important skill for ensuring seamless data access and integration in the vast realm of Linux system administration. In particular, among the various tools at our disposal, the /etc/fstab file is a linchpin for configuring different filesystems.

In this tutorial, we’ll deep dive into configuring network drives in Linux using the /etc/fstab file. Moreover, we’ll learn how to use the file for mounting network drives during system boot.

2. Understanding the Significance of /etc/fstab

The /etc/fstab file serves as a cornerstone in the orchestration of filesystem mounts on Linux systems. As a configuration file, it holds the blueprint for mounting different partitions and drives with specific parameters.

In particular, whether it’s local disk partitions, external drives, or network shares, the /etc/fstab file dictates how such entities should be integrated into the filesystem hierarchy.

Moreover, the mount command consults the /etc/fstab configuration file during the boot process or when manual mounts are initiated. By doing so, it provides a systematic approach to managing diverse storage solutions.

In essence, let’s take a closer look to summarize what the /etc/fstab file is and why it’s essential:

  • /etc/fstab is a configuration file that contains information about various filesystems and their associated parameters
  • the mount command reads /etc/fstab at boot time or whenever we mount a filesystem manually
  • /etc/fstab defines how different partitions and with what options drives  and filesystems should be mounted

Since the /etc/fstab configuration files deals with mounted network drives, we may also need insights into navigating the network drive landscape.

3. Identifying Network Drive Information

Before delving into the intricacies of configuring network drives, we ought to first familiarize ourselves with the key elements that define a network drive setup:

  • network drive address: this refers to the location of the network drive, typically identified by an IP address or hostname
  • share name: the shared directory on the network drive that we intend to access or the root of the share
  • local mount point: the directory within our Linux system where the network drive will seamlessly integrate

These fundamental details form the foundation upon which we build our configuration, enabling us to tailor the setup to the specific needs of our system.

4. /etc/fstab Basic Configuration

In this section, we’ll check out the basic configurations of the /etc/fstab file.

4.1. Navigating Through /etc/fstab

Let’s start with a trivial example of how to configure a network drive in the /etc/fstab file:

$ sudo nano /etc/fstab

In the above snippet, we used the sudo command that enables us to have superuser privileges to view the contents of the /etc/fstab file. Furthermore, we utilized the nano command as our preferred text editor when navigating or amending the contents of the file.

As the output suggests, we have a view of the configurations present in the /etc/fstab file:

# /dev/sda1
UUID=12345678-9abc-def0-1234-56789abcdef0 /boot           ext4    defaults        0       2
# /dev/sda2
UUID=87654321-fedc-ba09-8765-43210fedcba9 /               ext4    errors=remount-ro 0       1
# /dev/sdb1
UUID=abcdefgh-ijkl-mnop-qrst-uvwxyzabcdef /mnt/data       ext3    defaults        0       2
# /dev/cdrom
/dev/cdrom        /media/cdrom0   udf,iso9660 user,noauto     0       0
# NFS Share   /mnt/nfs   nfs     defaults    0   0

Next, let’s further understand the hierarchy and organization of the /etc/fstab file:

  • device: identifies the UUID or device path and specifies the mounted partition or device
  • mount point: indicates the directory where the device or partition will be mounted in the filesystem
  • filesystem type: specifies the type of filesystem on the device or partition, such as ext4, nfs, and others
  • options: defines various options for mounting the filesystem, such as read-only, read-write, and other specific settings
  • backup operation: the dump command uses this field to determine whether the filesystem should undergo a backed-up operation, where a value of 0 indicates no backup
  • filesystem check order: the fsck command uses this field to determine the order in which filesystem checks are performed at boot time

Nevertheless, we need to be cautious when editing the fstab file, as incorrect configurations can lead to boot issues.

4.2. Adding a Mount Point to /etc/fstab

At this point, we’ll modify the /etc/fstab file to mount a network share using the Common Internet File System (CIFS) protocol:

//  /mnt/network_drive  cifs  defaults  0  0

First, we added the above line to the fstab configuration file:

Accordingly, // specifies the network address and share name of the remote filesystem. In this example, it’s a network share located at IP address with the share name share. Furthermore, the directory where the network share will be mounted in the local filesystem is /mnt/network_drive.

The keyword cifs indicates the type of the share. In addition, the first 0 in the above snippet indicates no backups. Finally, the second 0 indicates that the filesystem won’t be checked during boot.

To exit, we press Ctrl+X, then type y to confirm the changes, and finally press Return to save.

4.3. Mount and Verify

After we amend the fstab configuration file, we can utilize the mount command to execute the configured mounts in the file:

$ sudo mount -a
[sudo] password for your_username: 

In the above example, we used the sudo command to perform the mount operation. The mount -a command also serves as our litmus test, mounting all filesystems mentioned in fstab file to verify the absence of syntax errors in our configuration.

Next, let’s confirm the results of this operation by viewing our mounted filesystems:

$ df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda1            20G   4.5G   15G  24% /
//  100G   20G   80G  20% /mnt/network_drive

The df command provides insights into mounted filesystems. Thus, we can confirm the presence of the network drive in the output, validating the successful integration.

Particularly, we see that we successfully mounted the network share and data about disk space usage. Moreover, the specific values for Size, Used, Avail, and Use% will depend on our actual network share content and capacity.

5. CIFS Advanced Security Configuration

For heightened security, we explore an advanced configuration by storing credentials in a separate file called .smbcredentials.

5.1. smbcredentials

In essence, the .smbcredentials file is important for securely managing authentication details when accessing network shares via the CIFS protocol on Linux.

When dedicating a separate file for credentials, we enhance the security by restricting access to the owner of that file and minimizing the risk of unauthorized exposure. The file’s restricted permissions, typically set to allow only the owner to read and write, contribute to a more secure authentication process.

Furthermore, the integration with the fstab file ensures centralized and automated management of credentials, facilitating secure and convenient mounting of network shares during system startup.

Overall, the .smbcredentials file is a key component in organizing and safeguarding sensitive authentication information in Linux systems.

5.2. Environment Setup

Let’s employ the method of creating a .smbcredentials file in our home directory:

$ nano ~/.smbcredentials

Here, we used nano to create the smbcredentials file. Furthermore, the ~ symbol represents our home directory in Linux.

Next, we type in our credentials:


After we set our credentials, it’s time to set the permissions of the file:

$ chmod 600 ~/.smbcredentials

In the above example, we use the chmod command to assign the permissions that we want to the .smbcredentials file. In essence, we set the permission to 600, which sets read and write permissions only for the owner of the file, ensuring that no one else can access the credentials.

5.3. Mounting Share

As we did before, we append our mount point and settings to the fstab file:

$ sudo nano /etc/fstab
//  /mnt/network_drive  cifs  credentials=/home/your_username/.smbcredentials,iocharset=utf8,sec=ntlm  0  0

In the above snippet, we opened the fstab file with nano text editor and added a line to it. However, this example differs from the one we used in the previous section:

  • credentials are in the .smbcredentials file
  • the UTF-8 character set is used
  • employs the NTLM security protocol

Finally, similar to what we’ve done in the previous section, we perform the mount operation with mount:

$ sudo mount -a
$ df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda1            20G   4.5G   15G  24% /
//  100G   20G   80G  20% /mnt/network_drive

The output of the df command confirms the successful mounting of the share.

6. Conclusion

In this article, we talked about /etc/fstab and successfully configured a network drive in Linux using the fstab file.

First, we learned why network drives are important and how to verify our results. Then, we talked about enhancing security and restricting permissions when mounting CIFS shares. Finally, we saw how to make use of the .smbcredentials file and set up our environment before mounting the CIFS share.

1 Comment
Inline Feedbacks
View all comments
Comments are closed on this article!