In this tutorial, I show you how to fix the Mount CIFS Permission Denied error on Linux.
Table of Contents
- Mount CIFS Permission Denied Error
- Step 1 - Installing CIFS Utils
- Step 2 - Creating a Mount Point
- Step 3 - Editing the fstab file
- Step 4 - Creating the .smbcredentials file
- Wrapping up
Mount CIFS Permission Denied Error
The error occurs mostly because you don't provide sufficient credential information, specifically which Domain you are in. Most Tutorials out there only mention username and password when editing the .smbcredentials file. But let me take you through the process from the beginning.
Step 1 - Installing CIFS Utils
To mount a CIFS share on Linux, we first need to install cifs-utils. Let's get started with that.
sudo apt-get install cifs-utils -y
It should probably be pre-installed in most distros anyway.
Step 2 - Creating a Mount Point
Next, we need to create the directory where we want to Mount our Share in. You can later find the Share in this Directory. For this example, we will mount the imaginary "Photos" share.
sudo mkdir /media/share/Photos
Step 3 - Editing the fstab file
That we don't have to mount our Share again after each reboot, we have to edit the fstab file to make the Share mount automatically after each reboot. But first, we make a backup of this file in case something goes wrong.
sudo cp /etc/fstab /etc/fstab.old
That done, we edit our fstab file.
sudo gedit /etc/fstab
And paste this line at the end of the file (all in one line)
Code language: JSON / JSON with Comments (json)
//YourServer/Photos /media/share/Photos/ cifs vers=2.0,credentials=/home/YourLinuxUsername/.smbcredentials,iocharset=utf8,gid=1000,uid=1000,file_mode=0777,dir_mode=0777 0 0
Of course, adjust accordingly to your own Server and YourLinuxUsername! We will create the .smbcredentials file next.
By default, you will have the gid=1000 and uid=1000. That's your Group & User ID, but to make sure that those values are the same in your system, double-check it by typing:
If all is correct, hit CTRL+S to Save the fstab file and close it.
Step 4 - Creating the .smbcredentials file
We could enter our username directly into our fstab file, but that would not be safe as someone could clearly read our Username and Password in this unencrypted file. Therefore, we are going to create a separate file containing this information.
Code language: CSS (css)
sudo gedit .smbcredentials
And here is the key point to fixing the Mount CIFS Permission Denied error. Most guides simply state to enter Username and Password into this file, but you also have to enter your Domain!
So paste this into your .smbcredentials file:
username=yourusername password=yourpassword domain=yourdomain
Save & Close the file.
Now we just make the .smbcredentials file so that only the root user can read its contents.
sudo chmod 600 ~/.smbcredentials
Step 5 - Mounting the Share
Now when everything is done, try to mount the share by typing
sudo mount -a
And your share should now be successfully mounted! If there are still some errors, try rebooting your system and see again if the Share was mounted. The share should be located in your media/share/Photos folder.
It took me a while to figure out this error. I use a Synology NAS and had to set vers=2.0 in the fstab file. If you still encounter problems, try changing vers to 1.0 or 3.0. Let me know in the comments below if this solution worked for you!