Monthly Archives: November 2011

Changing ownership on a Linux CIFS share

This is one of those very simple things that just doesn’t seem to come up right away in Google search results.  Especially if you’re new to how Linux handles ownership and file permissions.

Working on the server I mentioned in my last post, I couldn’t get some of the applications I am using to properly access my NAS mount point.  Specifically, any time permissions were trying to be changed it would fail because the program was running as my user, and not root.  Normally I’d just run the scripts as root, but I felt it’d be more secure to instead change those mounts to my user account.  Especially since these would be running unattended.  Also, I wanted fstab to bring up the drives already associated with my account.

First and foremost: Using chown on a mounted share will not work.  The command will behave as though it succeeded, but the ownership will not change.  Ownership can only be assigned at mount time.  Be ready to umount the share you wish to change ownership on.

The trick is to add the gid and uid to the fstab line for the mount.  So this:

//192.168.1.100/share      /media/nasshare          cifs    guest,rw,nounix,iocharset=utf8,file_mode=0770,dir_mode=0770 0 0

Becomes this:

//192.168.1.100/share      /media/nasshare          cifs    guest,rw,nounix,iocharset=utf8,gid=1000,uid=1000,file_mode=0770,dir_mode=0770 0 0

The above examples give full access to a share with no credentials, so it’s only shown as an example. But the gid and uid parameters specify the user and group that the share will mount as.

The source I’ve been using to learn all of these mounting procedures is here:
http://ubuntuforums.org/showthread.php?t=288534

Any more information needed about mounting shares in Ubuntu can be found there.