{"id":1522,"date":"2015-12-17T13:28:21","date_gmt":"2015-12-17T21:28:21","guid":{"rendered":"http:\/\/systemsolver.com\/StatlerBlog\/?p=1522"},"modified":"2015-12-17T13:28:21","modified_gmt":"2015-12-17T21:28:21","slug":"linux-samba-fix-usersgroupspermissions","status":"publish","type":"post","link":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/2015\/12\/17\/linux-samba-fix-usersgroupspermissions\/","title":{"rendered":"LInux Samba fix users\/groups\/permissions"},"content":{"rendered":"<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">My problem is that group and user permissions for the group get changed or created wrong when a file is changed or created by some users.<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">I want a specific group of users to have read\/write permissions to every subdirectory and files.<\/p>\n<p><a href=\"http:\/\/linuxcommand.org\/man_pages\/setfacl1.html\">http:\/\/linuxcommand.org\/man_pages\/setfacl1.html<\/a><\/p>\n<p>Good examples:<\/p>\n<p><a href=\"http:\/\/www.calculate-linux.org\/main\/en\/setting_filesystem_acl\">http:\/\/www.calculate-linux.org\/main\/en\/setting_filesystem_acl<\/a><\/p>\n<h2 style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">I did this:<\/h2>\n<p>===<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">On the samba serverm in \/etc\/Samba\/smb.conf\u00a0 just before the share definitions at the end of the file<br \/>\n<code>force group = users<\/code><\/p>\n<p>===<\/p>\n<p><code>sudo gedit \/etc\/fstab<\/code><\/p>\n<p>add acl to list of options on all mounts then remount:<\/p>\n<p><code>sudo mount -a<\/code><\/p>\n<p>*- prepare existing files\/folders<br \/>\n<code>sudo chgrp -R users \/mnt\/Files\/a-PI\/---.test2 #change group folders and files belong to<br \/>\nsudo chmod -R g+rwX \/mnt\/Files\/a-PI\/---.test2 #change the current folders\/docs to group read\/write, capital X changes only folders and executables to executeable<\/code><\/p>\n<p>*- set default for new folders\/files<br \/>\n<code>sudo setfacl -R -m \"default:group:groupname:rwx\" \/mnt\/Files\/a-PI\/---.test2 #group rw but not setting default group<br \/>\nsudo chmod -R g+s \/mnt\/Files\/a-PI\/---.test2 #set SGID so new items belong to parent group<\/code><\/p>\n<p>without comments:<\/p>\n<p>&nbsp;<\/p>\n<p><code>sudo chgrp -R users \/mnt\/Files <\/code><\/p>\n<p><code>sudo chmod -R g+rwX \/mnt\/Files <\/code><\/p>\n<p><code>sudo setfacl -R -m \"default:group:groupname:rwx\" \/mnt\/Files <\/code><\/p>\n<p><code>sudo chmod -R g+s \/mnt\/Files<\/code><\/p>\n<p>&nbsp;<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">&#8212; maybe not so much the below info<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">Then as root:<br \/>\nsu<br \/>\nchgrp users \/media\/Office-Files &amp;&amp; chmod g+s \/media\/Office-Files<br \/>\nchgrp users -R \/media\/Closed # not -&gt; &amp;&amp; chmod g+s \/media\/Closed see Note<br \/>\nchgrp users \/media\/Local-backup &amp;&amp; chmod g+s \/media\/Local-backup<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">NOTE: setting the sticky bit was an error, it prevents anyone but the user from deleting<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">to remove the sticky bit<\/p>\n<pre style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">sudo chmod g-s -R \/dir<\/pre>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">To change group permissions to read, write, execute<\/p>\n<p><code>chmod -R g+rwx DirectoryName<\/code><\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">and this [<a href=\"http:\/\/serverfault.com\/questions\/444867\/linux-setfacl-set-all-current-future-files-directories-in-parent-directory-to\">from here<\/a>]:<\/p>\n<pre style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\"><code style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">sudo setfacl -Rdm g:groupnamehere:rwx \/base\/path\/members\/\nsudo setfacl -Rm g:groupnamehere:rwx \/base\/path\/members\/\n<\/code><\/pre>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\"><b style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">R<\/b> is recursive, which means everything under that directory will have the rule applied to it. <br style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\" \/> <b style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">d<\/b> is default, which means for all future items created under that directory, have these rules apply by default. <b style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">m<\/b> is needed to add\/modify rules.<\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">The first command, is for new items (hence the d), the second command, is for old\/existing items under the folder. Hope this helps someone out as this stuff is a bit complicated and not very intuitive.<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">Restart samba server<br \/>\n<code>sudo service smbd restart<\/code><\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">log out log in?<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">Now make sure new user names are in the group &#8216;users&#8217;<\/p>\n<h4 style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">These are the possible solutions I considered:<\/h4>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\"><a href=\"http:\/\/www.linuxquestions.org\/questions\/linux-server-73\/ownership-on-new-files-in-group-samba-share-set-badly-898489\/\">http:\/\/www.linuxquestions.org\/questions\/linux-server-73\/ownership-on-new-files-in-group-samba-share-set-badly-898489\/<\/a><\/p>\n<p style=\"color: black ! important; padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">To cause all files henceforth created in <span style=\"font-family: Courier New;\">\/samba\/founders<\/span> to be owned by the &#8220;<span style=\"font-family: Courier New;\">founders<\/span>&#8221; group, do the following.<\/p>\n<div style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">\n<div class=\"smallfont\" style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">Code:<\/div>\n<p class=\"bbcodeblock\" dir=\"ltr\" style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">chgrp founders \/samba\/founders &amp;&amp; chmod g+s \/samba\/founders<\/p>\n<\/div>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">So maybe for me this would be:<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">chgrp \/media\/Office-Files users \/media\/Office-Files &amp;&amp; chmod g+s \/media\/Office-Files<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\"><a href=\"https:\/\/www.samba.org\/samba\/docs\/using_samba\/ch09.html\">https:\/\/www.samba.org\/samba\/docs\/using_samba\/ch09.html<\/a><\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">However, if you&#8217;re creating a shared directory for group access, you need to perform a few more steps. Let&#8217;s take a stab at a group share for the accounting department in the smb.conf file:<\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">[accounting]<br style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\" \/> comment = Accounting Department Directory<br style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\" \/> writable = yes<br style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\" \/> valid users = @account<br style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\" \/> path = \/home\/samba\/accounting<br style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\" \/> create mode = 0660<br style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\" \/> directory mode = 0770<br style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\" \/> The first thing we did differently is to specify @account as the valid user instead of one or more individual usernames. This is shorthand for saying that the valid users are represented by the Unix group account. These users will need to be added to the group entry account in the system group file ( \/etc\/group or equivalent) to be recognized as part of the group. Once they are, Samba will recognize those users as valid users for the share.<\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">In addition, you need to create a shared directory that the members of the group can access and point to it with the path configuration option. Here are the Unix commands that create the shared directory for the accounting department (assuming \/home\/samba already exists):<\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\"># mkdir \/home\/samba\/accounting<br style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\" \/> # chgrp account \/home\/samba\/accounting<br style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\" \/> # chmod 770 \/home\/samba\/accounting<br style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\" \/> There are two other options in this smb.conf example, both of which we saw in the previous chapter. These options are create mode and directory mode. These options set the maximum file and directory permissions that a new file or directory can have. In this case, we have denied all world access to the contents of this share. (This is reinforced by the chmod command, shown earlier.)<\/p>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\"><a href=\"http:\/\/unix.stackexchange.com\/questions\/164884\/how-to-set-default-group-for-files-created-in-samba-share\">http:\/\/unix.stackexchange.com\/questions\/164884\/how-to-set-default-group-for-files-created-in-samba-share<\/a><\/p>\n<p style=\"color: black ! important; padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">One solution: In<\/p>\n<pre style=\"padding-left: 60px;\" data-blkn-colour=\"rgba(51,51,51,1)\"><code style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">\/etc\/samba\/smb.conf\nAdd these options to the <\/code><code style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">[global]<\/code> section:\n<\/pre>\n<p style=\"padding-left: 60px;\" data-blkn-colour=\"rgba(51,51,51,1)\"><code style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">force user = rolf force group = coders<\/code><\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">Another solution:<\/p>\n<p style=\"padding-left: 60px;\" data-blkn-colour=\"rgba(51,51,51,1)\">you could try adding sticky bit for the group on that folder<\/p>\n<pre style=\"padding-left: 60px;\" data-blkn-colour=\"rgba(51,51,51,1)\"><code style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">chmod 2770 foldername\nfind foldername -type d -exec chmod g+s {} \\;<\/code><\/pre>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\"><a href=\"http:\/\/askubuntu.com\/questions\/97669\/i-cant-get-samba-to-set-proper-permissions-on-created-directories\">http:\/\/askubuntu.com\/questions\/97669\/i-cant-get-samba-to-set-proper-permissions-on-created-directories<\/a><\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">&#8212;&#8212;&#8212;&#8211;See following post from this web site&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">I think you need to use the following parameters:<\/p>\n<pre style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\"><code style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\"># I changes the permissions to rw-rw-r--\n# You should be able to change them to 775 if you need the files to\n# be executable\ncreate mask = 664\nforce create mode = 664\nsecurity mask = 664\nforce security mode = 664\n\n# I set the SGID flag here as I thought this is what you wanted\n# You could change to 0775\ndirectory mask = 2775\nforce directory mode = 2775\ndirectory security mask = 2775\nforce directory security mode = 2775\n<\/code><\/pre>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">I was looking for a nice explanation of how these settings work, but could not find anything better then <a href=\"http:\/\/manpages.ubuntu.com\/manpages\/precise\/man5\/smb.conf.5.html\" data-blkn-colour=\"rgba(221,72,20,1)\">man smb.conf<\/a><\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">&#8212;&#8212;&#8212;-This one might be the true answer&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<div class=\"post-text\" style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">After a lot of trial and error, this is the correct code to share samba dir using SGID and unix groups. If user connects anonymously he gets r\/o, if he logs in and is a member of assigned group he gets r\/w.<\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">I have group named &#8216;admin&#8217; set as primary group to users with write privileges, everyone else gets read only rights.<\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">I force user to nobody, so different people working on same files don&#8217;t interfere with each other.<\/p>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">I set chmod 2755 on shared directory, so it inherits created directories with the same group &#8216;admin&#8217;<\/p>\n<pre style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\"><code style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">$ chmod -R 2755 \/home\/shares\/test\n<\/code><\/pre>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">Checking if all is good:<\/p>\n<pre style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\"><code style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">$ stat \/home\/shares\/test\nAccess: (2755\/drwxr-sr-x)  Uid: (65534\/  nobody)   Gid: ( 1001\/   admin)\n<\/code><\/pre>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">Relevant part of \/etc\/samba\/smb.conf:<\/p>\n<pre style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\"><code style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">[test]\n        comment = test\n        path = \/home\/shares\/test\n        force user = nobody\n        read only = No\n        create mask = 0664\n        force create mode = 0664\n        directory mask = 02775\n        force directory mode = 02775\n<\/code><\/pre>\n<p style=\"padding-left: 30px;\" data-blkn-colour=\"rgba(51,51,51,1)\">This post put me on right track, but testparm revealed 4 incorrect directives, so I&#8217;m sharing fixed config here. In samba, the less directives you specify the better it works.<\/p>\n<\/div>\n<p style=\"color: black ! important;\" data-blkn-colour=\"rgba(51,51,51,1)\">end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My problem is that group and user permissions for the group get changed or created wrong when a file is changed or created by some users. I want a specific group of users to have read\/write permissions to every subdirectory and files. http:\/\/linuxcommand.org\/man_pages\/setfacl1.html Good examples: http:\/\/www.calculate-linux.org\/main\/en\/setting_filesystem_acl I did this: === On the samba serverm in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6],"tags":[],"class_list":["post-1522","post","type-post","status-publish","format-standard","hentry","category-general","category-linux"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/comments?post=1522"}],"version-history":[{"count":0,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1522\/revisions"}],"wp:attachment":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/media?parent=1522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/categories?post=1522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/tags?post=1522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}