There are a lot of questions surrounding how to properly mount a CIFS share on a Linux machine. Most of them involve Ubuntu users.
One of the most common problems I see is that normal users can’t mount a CIFS share that they would otherwise have access to; instead they get “mount requires root.” Then they force it through by prefixing it with “sudo” and run into even more problems. Here’s a quick list of caveats to consider if you’re having trouble mounting a FreeNAS (or Samba, or Windows) share on a Ubuntu machine:
Ubuntu requires additional packages.
For some reason, a stock Ubuntu install will pretend to be able to mount a SMB/CIFS share if you issue the right commands, but the actual mount will fail and you will be scratching your head wondering why. This is because stock Ubuntu does not ship with all the packages you need to interface with CIFS shares, namely cifs-utils.
This sounds like paranoia, but I’m not kidding. I remember having similar issues with Ubuntu 8 and it’s still an issue now that we’re on 14.
Amusingly enough, you’ll probably hammer your share with invalid authentication credentials so many times as a result of this that your account will get locked out and make things even more confusing.
Avoid that and simply install what you need with a quick apt-get:
sudo apt-get install cifs-utils
Don’t use “mount -t cifs”
Conventional wisdom from 1999 or so will have you believe you mount a CIFS share like any other filesystem. On some distributions, this may be the case. And in fact, this may have been the case with older versions of SMBFS. On Ubuntu, this is wrong. Ubuntu no longer uses traditional SMBFS, and If you attempt to mount your CIFS share with a non-root user using “mount -t cifs,” you will run into the next problem:
Normal users can’t mount a CIFS share.
To fix this, you may have been told that all you have to do is add the “users” flag to a corresponding entry in /etc/fstab. With any other kind of filesystem, this would work, but there are more steps involved than just this. See below.
I get “permission denied” when creating or modifying files on the CIFS share.
Yeah, that’s either because you mounted the share using “sudo mount -t cifs” and thus only root can make changes to it now, or because the permissions on the remote side are improperly set for the credentials you provided.
So how do I fix this? I have more important things to do.
I’m going to assume you have a functional share with appropriate permissions that work fine when you connect with a Windows machine. I’ll also assume you have separate Windows credentials for accessing the share.
Add the share to /etc/fstab
You do need to add the share to /etc/fstab if you want normal users to be able to mount it, and you do need to give that share the “users” flag. Do a “sudo nano /etc/fstab” and add an entry like:
//192.168.1.100/data /media/corpnet cifs username=johnny,domain=sealab,noauto,rw,users 0 0
Doing it this way, the share is not automatically mounted and the user will be prompted for Windows credentials when they do try to mount. You could hard-code a “password=thisismypassword” field there too, remove the “noauto” flag and thus have the share mount automatically but I don’t believe in hard-coding passwords. On my domains, Windows passwords expire regularly so fstab would require manual changes fairly often. Foist the responsibility of providing current credentials on the user.
Make sure you have functional rights to your mount point
This much is standard mounting practice, but you need to make sure you actually have permissions for the directory into which you are trying to mount your CIFS share. Trying to mount onto /home? Not going to work. Even most of the /media directories don’t allow you much access by default. You should be mounting into an empty directory that you have permissions for.
Create a safe place to mount the share and give yourself permissions for it.
sudo mkdir /media/corpnet sudo chown -R johnny:johnny corpnet sudo chmod -R 774 corpnet
Mount it using mount.cifs
Again, don’t use “mount -t cifs” like you might think based on tradition that’s older than your children. Use the separate non-root utility “mount.cifs” to mount your share as a normal user. It works almost the same way and you don’t need root access for it as long as you put the proper entry in /etc/fstab.
mount.cifs //192.168.1.100/data /media/corpnet (umount /media/corpnet)
From there, you should be good to go. It will prompt for your Windows password– a minor inconvenience, but avoids having your password stored in cleartext and should prevent other users on the machine from mapping the share using your credentials.
Still having problems?
- If you can’t get into the share at this point, it’s probably a permissions problem with your mount point.
- If you can get into the share but there’s nothing there, or you get “permission denied” when trying to create or modify files:
- Check the permissions on your mount point first.
- Expect that it is most likely a permissions issue with your remote share. Troubleshooting this is beyond the scope of this article, but it would be prudent to first make sure you can access and write to your shares from a Windows machine.
- Did you mount the share using any form of “sudo mount” command? If so, only root can view/make any changes to the remote files. You weren’t supposed to do that.