A while back, I bought a QNAP NAS drive for backing up my server and other machines which are attached to the network. Having created a number of shared folders on the NAS, I had shortcuts to them available to me via SAMBA, but I wanted to configure my desktop machine so that the folders were permanently mounted.
So, the first step was to make sure that SMBFS was installed and up to date:
sudo apt-get install smbfs
Once the installation was complete, rather than store the connection details in plain sight, I wrote a text file which would contain the details
sudo gedit .nascredentials
The text file includes the user name and password to connect to the NAS (which are different from my Linux username and password):
To make sure that the file was then restricted, I changed the access permissions for the credentials file so that only root user could read it
sudo chmod 600 .nascredentials
The next step was to create a mount point folder, which was accessible to any user on the system
sudo mkdir /media/nas sudo chmod 777 /media/nas
After this, I edited the fstab file to include the mounting commands (note that the text should all be on one line, but I’ve had to include line breaks here for formatting reasons!)
sudo gedit /etc/fstab //<NAS IP Address>/backups /media/nas cifs credentials=/home/myuser/.nascredentials,dir_mode=0777, file_mode=0777,umask=000,uid=myuser 0 0
This does rely on the NAS drive having a fixed IP address, and “backups” is the name of the samba share name.
Finally, rather than reboot, I only had to execute the following command to mount the new share
sudo mount -a
If the NAS is not switched on when the computer starts, then the drive won’t be mounted – if that happens, then I just need to run the last command to mount the folder again.