Skip to content

Automatically mount your NAS share

Simple configuration to enable automatic and reliable mounting of a network share

📅 Created: Dec 6, 2025•🕒 Updated: Dec 23, 2025

Somehow it's not trivial to find a simple and straightforward guide to how to best set up a network share (e.g. a folder on your NAS) in Linux, which is why I wrote this.

Tl;Dr for experienced people ​

The following fstab preset will likely be what you are looking for. If you don't know what this means, skip this part!

//<nas-ip-or-hostname>/<share>	/nas/<share>	cifs	x-systemd.automount,noauto,user,uid=<user>,gid=<user>,credentials=/etc/cifs-credentials 0 0

Be sure to:

  1. replace <user> with your local username
  2. create the required folders for the mount
  3. create the creddentials file /etc/cifs-credentials (with 1. line username=... and 2. line password=...)
  4. apply chmod 600 to that file
  5. reload your systemd daemon and restart remote-fs.target

done.

Full Tutorial ​

For the sake of simplicity, I will assume you have a Synology NAS and name things accordingly. But this will work regardless of what NAS you have, just change folder names for whatever NAS and naming convention you have.

1. Creating local folders ​

So, we want to make our NAS share available on our system, but how?
Firstly, we need a local folder. This folder will then be used to mount the NAS-folder, making it look like it's on your system.

Let's say you have the following shares on your NAS:

\\Synology
├── home
├── documents
└── movies

To connect to all these folders, let's create the following local folder structure on the PC:

/synology
├── home
├── documents
└── movies

First, create the parent-folder

$ sudo mkdir /synology

Then create one sub-folder for every share you want, in our case:

$ sudo mkdir /synology/home
$ sudo mkdir /synology/documents
$ sudo mkdir /synology/movies

2. Save the NAS-login to your system ​

Next, we will need to store our login credentials for our NAS, such that our computer can use it to esthablish a connection. Use the same credentials that you would type in when connecting to your NAS via a file browser.

Let's create the file /etc/smb-credentials by typing the following command:

$ sudo edit /etc/smb-credentials

and enter the login credentials such that the file looks like this:

username=peter
password=supersecurepassword123

IMPORTANT: As this file includes clear-text login credentials, we need to protect it. Enter the following command to lock this file down so only our system and administrators can access it:

shell
$ sudo chmod 600 /etc/smb-credentials

If you intend to connect multiple remotes with different logins, you can simply create more files:

shell
# first file
$ sudo edit /etc/synology-smb-credentials
$ sudo chmod 600 /etc/synology-smb-credentials
# second file
$ sudo edit /etc/truenas-smb-credentials
$ sudo chmod 600 /etc/truenas-smb-credentials

3. Setting up the mount ​

Lastly, let's tell our system to use the local folders and credentials we just set up to mount the appropriate shares from our NAS.

3.1 Preparing the config ​

Open a graphical text editor of your choice and copy the following line into the editor:

//<ip>/<share>		/synology/<share>		cifs		x-systemd.automount,noauto,user,uid=<user>,gid=<user>,credentials=/etc/smb-credentials 0 0

In your graphical editor, replace/fill-in the following sections:

  • //<ip>/<share>: This should point to the IP/hostname of your NAS and the share you want to use
  • /synology/<share> Use your respective local folder you created in step 1
  • uid=<user>: the part of <user> should be replaced by your local username of the user on your PC.
  • gid=<user>: the same, replace <user> with your local username.

Now repeat this for all the shares you want to mount.

Example 1 ​

Let's assume the following:

  • the local folders were your created was /synology/home and /synology/documents
  • your NAS uses the IP 192.168.1.23
  • your credential file is at /etc/smb-credentials
  • your local username is peter

For these assumptions, your file should look roughly like this:

//192.168.1.23/home        /synology/home		     cifs		x-systemd.automount,noauto,user,uid=peter,gid=peter,credentials=/etc/smb-credentials 0 0
//192.168.1.23/documents   /synology/documents    cifs		x-systemd.automount,noauto,user,uid=peter,gid=peter,credentials=/etc/smb-credentials 0 0

Example 2 ​

This time your NAS is a TrueNAS, you only refernce it by it's hostname and your respective local folders and credential file are named differently:

//TRUENAS/home        /nas/home		     cifs		x-systemd.automount,noauto,user,uid=peter,gid=peter,credentials=/etc/truenas-smb-credentials 0 0
//TRUENAS/public      /nas/public       cifs		x-systemd.automount,noauto,user,uid=peter,gid=peter,credentials=/etc/truenas-smb-credentials 0 0

3.2 Edit the fstab ​

We will now edit the existing file /etc/fstab. Be sure to be careful and don't delete things that are already in there. Errors can result in your system unable to start at next boot.

After you enter the file, navigate to the end and make some new lines to put some space between the configuration of your system and our addition.

Open the file in an editor with $ sudo edit /etc/fstab and go into a new, empty line at the bottom of the file. For safety, make some new empty lines to put some space between the configuration of your system and what we will add now.

Next, copy what you just prepared in your graphical text editor and paste it into the file, roughly like this:

shell
# This is stuff that is already here and was configures by your system.
# DO NOT CHANGE ANY OF THIS, EVEN IF LOOKS WAY DIFFERENT FROM THIS 
dev/system/os    /                       btrfs  defaults                      0  0
UUID=4076-E522       /boot/efi               vfat   utf8                          0  2
(...)
# Let's put some space for safety between the system stuff and our changes




# Now come our changes:
//192.168.1.23/home        /synology/home		     cifs		x-systemd.automount,noauto,user,uid=peter,gid=peter,credentials=/etc/smb-credentials 0 0
//192.168.1.23/documents   /synology/documents    cifs		x-systemd.automount,noauto,user,uid=peter,gid=peter,credentials=/etc/smb-credentials 0 0
//192.168.1.23/movies      /synology/movies       cifs		x-systemd.automount,noauto,user,uid=peter,gid=peter,credentials=/etc/smb-credentials 0 0

Then simply save and exit. If you are using nano it's Strg+X (and then Y to save and Enter to confirm).

4. Activating the changes ​

You could just restart your PC. But if you don't want to, just enter these commands to load and activate our changes:

shell
$ sudo systemctl daemon-reload
$ sudo systemctl restart remote-fs.target

Done ​

If everything went fine, you should now find the NAS shares you set-up in the respective folders on your system, so /synology/home, /synology/documents and so on. Again, this may differ if you used different folder names.

You should also find your NAS folders shown in your graphical file managers directly. Most of them detect these mounts and display them somewhere on the left side of the window.