Configuring the permissions of a Samba share

Posted by

Samba share permissions can be a bit fiddly. The user and group IDs which own the file on the Samba server will propagate over to the client machines, which will enforce local permissions themselves.

Ideally, you want to have the same users/groups on all machines. This isn’t always practical but could be achieved with a config management tool such as Puppet or SaltStack, or indeed by backing your local users from an LDAP server.

If this is not possible, the following is suggested:

On your Samba server

  • Create a group which will own all the files, for example samba-users
  • Add all of your Samba users to the group you created – e.g. adduser downloader samba-users
  • Chown all of your shared files and folders to root:samba-users
  • Chmod all of your shared files to 660
  • Chmod all of your shared folders to 770
  • Add the below to the config for your share to enforce the above for all new files and folders:
create mask = 0664
force create mode = 0664
directory mask = 0775
force directory mode = 0775
force group = samba-users

On your client server(s)

  • Create a group which will be able to access all the files on the share, for example samba-users
  • Obtain the group ID (GID) from /etc/group for this group
  • In the mount options of the share (in /etc/fstab) add the uid 0 (root) as in the below example
  • In the mount options of the share (in /etc/fstab) add the gid as in the below example where the GID is 1002
//192.168.1.123/downloads /mnt/downloads  cifs    username=downloader,password=foobarbaz,iocharset=utf8,uid=0,gid=1002       0       0

If you u(n)mount and remount the share you will see that all the files are now owned by the group you specified in fstab.

Disclaimer

There might be a better way… feel free to comment if you know what it is.

Leave a Reply

Your email address will not be published. Required fields are marked *