Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 25, 2025
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.
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:
Since the /etc/fstab configuration files deals with mounted network drives, we may also need insights into navigating the network drive landscape.
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:
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.
In this section, we’ll check out the basic configurations of the /etc/fstab file.
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
192.168.1.100:/mnt/nfs_share /mnt/nfs nfs defaults 0 0
Next, let’s further understand the hierarchy and organization of the /etc/fstab file:
Nevertheless, we need to be cautious when editing the fstab file, as incorrect configurations can lead to boot issues.
At this point, we’ll modify the /etc/fstab file to mount a network share using the Common Internet File System (CIFS) protocol:
//192.168.1.100/share /mnt/network_drive cifs defaults 0 0
First, we added the above line to the fstab configuration file:
Accordingly, //192.168.1.100/share specifies the network address and share name of the remote filesystem. In this example, it’s a network share located at IP address 192.168.1.100 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.
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% /
//192.168.1.100/share 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.
For heightened security, we explore an advanced configuration by storing credentials in a separate file called .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.
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:
username=our_username
password=our_password
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.
As we did before, we append our mount point and settings to the fstab file:
$ sudo nano /etc/fstab
...
//192.168.1.100/share /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:
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% /
//192.168.1.100/share 100G 20G 80G 20% /mnt/network_drive
The output of the df command confirms the successful mounting of the share.
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.