github soundcloud rss
May 10, 2018
3 minutes read

A few /etc/fstab (file system table) variations:

//CONST/stash /home/const/mnt/stash cifs username=const,password=secret,vers=2.0,gid=1000,uid=1000

Using a credentials file (chmod 600 ~/.smbcredentials):

//CONST/stash /home/const/mnt/stash cifs credentials=/home/const/.smbcredentials,vers=2.0,gid=1000,uid=1000

How about from the command line?

mount -t cifs //CONST/stash /home/const/mnt/stash -o credentials=/home/const/.smbcredentials,vers=2.0,gid=1000,uid=1000

What happens to /home/const/mnt/stash if the share is unavailable? It goes back to being a local folder that you can use. You can change the permissions on this folder to read only for your user, so you don’t accidentally write data locally. Perhaps with chmod 000.

What happens if you mount on top of a folder that contains files and folders? Not much, except the local files and folders are hidden until the share is unmounted again. You can’t lose local files by mounting. See this.

There’s two set of permissions going on in the same folder: One when the share is mounted, and another when it isn’t. The permissions when it is unmounted do not particularily affect the mounting process, since the mounting process is done with root priveleges. This is why we have to set GID and UID manually, or else root gets all the permissons and your user account won’t be able to write anything. This concept used to be unintuitive and mysterious to me. Whenever something feels like that, I recommend reading read a few paragraphs from a book on the subject.

Recap recommended permissions:

  • Unmounted -> Set to chmod 000
  • Mounted -> Set gid=1000,uid=1000 when mounting. Run id to find your own UID and GID.

Another thing that is usually glossed over, is the fact that the mounting program is refering to cifs.

If you do not know this, navigating man mount can be frustrating. You are also supposed to know that the manual for mount -t cifs is found through man mount.cifs.

Why? Check out some history from the UNIX and Linux System Administration Handbook (chapter 22):

In 1996, a version called the Common Internet File System (CIFS) was released by Microsoft, mostly as a marketing exercise. Sun Microsystems had also entered the fray in 1996 with its WebNFS offering, and Microsoft saw an opportunity to market SMB with a more user-friendly implementation and name. CIFS introduced (often-buggy) changes to the original SMB protocol. As a result, Microsoft released SMB 2.0 in 2006 and then SMB 3.0 in 2012. Although it’s common within the industry to refer to SMB fileshares as CIFS, the truth is that CIFS was deprecated long ago; only SMB lives on.

What if you disconnect the share without unmounting?

umount -l /home/const/mnt/stash

How to debug? I don’t really know. Try sudo mount -a.

Chmod Calculator

Back to posts

comments powered by Disqus