I still don't quite understand how they work but after testing a little bit more I found that the following actually worked for what I wanted:

create mask = 0664
force create mode = 0664
directory mask = 0775
force directory mode = 0775

I'll us this for now... Let me know if you have an alternative that makes more sense.

Answer from rfgamaral on Stack Exchange
๐ŸŒ
Samba
samba.org โ€บ samba โ€บ docs โ€บ using_samba โ€บ ch08.html
Samba
When saving documents, many Windows ... so that members of the same Unix group can't edit them. Setting force create mode = 0660 will keep the new file editable by members of the group....
Discussions

networking - Why do "force create mode" and "force directory mode" parameters exist in smb.conf? - Unix & Linux Stack Exchange
I am reading How to Set Up a Network Shared Folder on Ubuntu With Samba. At the "Step 2: Configuring Samba" section the following configuration is given: [sambashare] comment= Network Sha... More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
Correct way for samba permissions?
I don't know if it matters, but you have a typo in a commented-out line: #recylce:exclude_dir = ... ^^^ More on reddit.com
๐ŸŒ r/sysadmin
5
1
June 26, 2024
/etc/samba/smb.conf: why exists the "force create mode" and "force directory mode" parameters?
Hello Friends About Samba I am reading the following valuable tutorial: How to Set Up a Network Shared Folder on Ubuntu With Samba At the Step 2: Configuring Samba section appears the following configuration [sambashare] comment= Network Shared Folder by Samba Server on Ubuntu path = ... More on itsfoss.community
๐ŸŒ itsfoss.community
0
0
March 22, 2024
Why do files I created in my Samba Share have the wrong permissions?
The folder has permissions 775, even though I specified 770. But you didn't specify a permission, you specified a mask. They aren't the same thing. Use this tool to convert between mask and permission: Permissions calculator More on reddit.com
๐ŸŒ r/linux4noobs
8
2
May 25, 2020
๐ŸŒ
Server Fault
serverfault.com โ€บ questions โ€บ 316787 โ€บ samba-default-permissions-not-respected
linux - Samba default permissions not respected - Server Fault
November 8, 2011 - I've tried a combination of all the possible configuration flags for create mode, create mask, force create mode force security mode, nothing works. So i finish by asking here. ... [homes] comment = Home Directories browseable = yes # By default, the home directories are exported read-only. Change the # next parameter to 'no' if you want to be able to write to them. read only = no # File creation mask is set to 0700 for security reasons. If you want to # create files with group=rw permissions, set next parameter to 0775. # create mask = 0660 create mode = 0660 # force security mode = 0660 # force create mode = 0660 # Directory creation mask is set to 0700 for security reasons.
๐ŸŒ
O'Reilly
oreilly.com โ€บ openbook โ€บ samba โ€บ book โ€บ ch05_03.html
5.3 File Permissions and Attributes on MS-DOS and Unix
Setting force create mask = 0660 will keep the new file editable by members of the group. This option sets the permission bits which Samba will force when a directory permission change is made or a directory is created. It's often used to force group permissions, as mentioned previously.
๐ŸŒ
SambaWiki
wiki.samba.org โ€บ index.php โ€บ Setting_up_Samba_as_a_Standalone_Server
Setting up Samba as a Standalone Server - SambaWiki
[demo] path = /srv/samba/demo/ read only = no force create mode = 0660 force directory mode = 2770 force user = demoUser force group = demoGroup
๐ŸŒ
Yaroslavl
linux.yaroslavl.ru โ€บ docs โ€บ serv โ€บ samba โ€บ using โ€บ ch05_03.html
[Chapter 5] 5.3 File Permissions and Attributes on MS-DOS and Unix
Setting force create mask = 0660 will keep the new file editable by members of the group. This option sets the permission bits which Samba will force when a directory permission change is made or a directory is created. It's often used to force group permissions, as mentioned previously.
๐ŸŒ
Samba
lists.samba.org โ€บ archive โ€บ samba โ€บ 2017-February โ€บ 206810.html
[Samba] Windows file directory creation permission confusion
February 23, 2017 - So make a new share, and test before ... lines from you smb.conf > force create mode = 0770 > force directory mode = 0770 > create mask = 0660 Add this line to the share....
Find elsewhere
๐ŸŒ
OneUptime
oneuptime.com โ€บ home โ€บ blog โ€บ how to configure samba share permissions on ubuntu
How to Configure Samba Share Permissions on Ubuntu
March 2, 2026 - [Department] comment = Department Files path = /srv/samba/department # Who can connect to this share valid users = @finance # Who can write (subset of valid users) write list = @finance # No guest access guest ok = no # Not read-only (allow writes for write list members) read only = no # Permissions for new files and directories # 0660 = owner rw, group rw, others none create mask = 0660 force create mode = 0660 # 0770 = owner rwx, group rwx, others none directory mask = 0770 force directory mode = 0770 # Force all files to be owned by the finance group force group = finance # Inherit permissions from parent directory instead of using the masks above inherit permissions = yes
๐ŸŒ
Stack Exchange
unix.stackexchange.com โ€บ questions โ€บ 772883 โ€บ why-do-force-create-mode-and-force-directory-mode-parameters-exist-in-smb-co
networking - Why do "force create mode" and "force directory mode" parameters exist in smb.conf? - Unix & Linux Stack Exchange
[sambashare] comment= Network Shared Folder by Samba Server on Ubuntu path = /home/your_username/sambashare force user = smbuser force group = smbgroup create mask = 0664 force create mode = 0664 directory mask = 0775 force directory mode = 0775 public = yes read only = no
Top answer
1 of 1
3

Often the issue is caused by enabling one of the following:

  • map archive (uses unix execute bit for owner)
  • map system (uses unix execute bit for group)
  • map hidden (uses unix execute bit for other)
  • inherit permissions causes samba to ignore create mask, etc
  • there's also inherit acls which should default to no

"File Permissions and Attributes on MS-DOS and Unix" in Chapter 8. Advanced Disk Shares explains the above nicely.

However, microsoft office products cause weird behaviour and trigger a bug/unexpected behaviour. Even with create mask and/or force create mode set and avoiding the above map or inherit option, I've seen group execute permissions get set when editing documents using microsoft office applications. This doesn't happen with other programs, e.g. edit a .txt file with notepad and permissions stay sane. Office doesn't just create files, it also messes a bit with temp files, renaming and permissions.

After a lot of digging around, it might be also be mixed up with a Samba POSIX ACL bug of sorts:

  • Old 2007 debian bug report "samba: misinterprets create mode with POSIX acls"
  • "Wrong behaviour for default ACLs" seems to be the most recent bug report for samba, but is sadly closed 'RESOLVED INVALID' (prematurely?).

Observed behaviour on the Linux side

The extended ACLs for an empty word docx file created via windows explorer context menu (not yet opened and saved by word)

$ getfacl test.docx 
# file: test.docx
# owner: tester
# group: tester
user::rw-
group::rw-
other::---

After saving via MS word 2016

$ getfacl test.docx 
# file: test.docx
# owner: tester
# group: tester
user::rw-
user:tester:rw-
group::rw-
group:tester:rw-
mask::rwx

When checking the samba config, on Ubuntu 16.04 LTS, it seems map archive is enabled by default, but that should use the owner's execute bit, not the group execute bit, so that wasn't the cause in my case

$ testparm -s -v 2>&1 | grep 'map archive'
map archive = Yes

Observed behaviour on the Windows side

Using SysInternals Process Monitor and comparing editing a .txt file with notepad.exe vs. a .docx file with WINWORD.EXE, the office suite does a lot of fancy footwork creating temp files, renaming, etc. In particular, unlike notepad.exe, WINWORD.EXE seems to fiddle with access control lists. As seen by procmon

SetSecurityFile
Information:    Group, DACL

So I suspect this is why the UNIX group permission gets fiddled with by microsoft office applications.

Deeper investigation required turning on windows file object security auditing to see what exactly changed. Event ID 4670 shows the the ~WRD0000.tmp permission changes applied (I think word uses this for periodic saving and recovery if it crashes).

Object:
    Object Server:    Security
    Object Type:    File
    Object Name:    C:\Users\<user>\Desktop\TestAudit\~WRD0000.tmp
    Handle ID:    0xfd0

Process:
    Process ID:    0x1ae4
    Process Name:    C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE

Permissions Change:
    Original Security Descriptor:
D:AI(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;FA;;;S-1-5-<SID>-1001)
    New Security Descriptor:
D:(A;;0x1200a9;;;WD)(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;FA;;;S-1-5-21-<SID>-1001)

The permission change in SDDL (Security Descriptor Definition Language) is a DACL (discretionary access control list part) where it appears an extra ACE (Access Control Entry) was added. ACE (A;;0x1200a9;;;WD) gets added right at the front. This is how I interpreted it:

  • A; meaning allow access, stayed the same
  • ; no inheritance
  • 0x1200a9; means FILE_GENERIC_READ | FILE_EXECUTE read & execute access
  • WD means the 'everyone' trustee

Then later on, the ~WRD0000.tmp gets renamed to test.docx which I saw in process monitor as a SetRenameInformationFile operation. So in the end test.docx ends up with some of the ACE changes word did for whatever reason.

๐ŸŒ
Reddit
reddit.com โ€บ r/sysadmin โ€บ correct way for samba permissions?
r/sysadmin on Reddit: Correct way for samba permissions?
June 26, 2024 -

HI

I was wondering if someone could shed some light,

Currently i have working fine my AD/DC using samba but every now and then i get odd permission issue

my question is what is the correct way or the correct config?

I was reading https://wiki.samba.org/index.php/Setting_up_a_Share_Using_Windows_ACLs

which it says,

If you set the shares permissions from Windows (The recommended way), you can add the line 'acl_xattr:ignore system acls = yes' to your share. If the line is added, Samba will ignore the standard Unix system ACL's (ugo). Once the line is added, running setfacl on the shares directory will not show any permission modifications you may have made from Windows. You must not add this line until you have set up the share permissions from Windows, otherwise you may find that you are denied permission to change the permissions from Windows.. Only add the line if you will only connect to share via Samba.

The part that says must not add this line until you have the share permissions do they mean all the folders permissions? what about the future permissions?

[shares]
        path = /usr/local/samba/shares
        comment = shares
        read only = no
        acl_xattr:ignore system acls = yes
        writable = yes
        read only = no
        force create mode = 0660
        create mask = 0777
        directory mask = 0777
        force directory mode = 0770
        access based share enum = yes
        hide unreadable = yes
 vfs objects = recycle full_audit shadow_copy2 acl_xattr
   recycle:repository = .trash/%U
   recycle:maxsize = 0
   recycle:versions = Yes
   recycle:keeptree = Yes
   recycle:touch = No
   recycle:directory_mode = 0704
#recylce:exclude_dir = /tmp /TMP /temp /TEMP /public /cache /CACHE
#recycle:exclude = *.TMP *.tmp *.temp ~$* *.log *.bak
shadow: snapdir = .zfs/snapshot
shadow: sort = desc
shadow: format = _%Y-%m-%d_%H:%M:%S
shadow: snapprefix = ^pyznap
shadow: delimiter = _
shadow:localtime = no
  full_audit:prefix = %u|%I|%m|%S
   full_audit:success = mkdirat renameat unlinkat
   full_audit:failure = none
   full_audit:facility = SYSLOG
   full_audit:priority = NOTICE
๐ŸŒ
Samba
lists.samba.org โ€บ archive โ€บ samba-ntdom โ€บ 2001-October โ€บ 019919.html
File permissions
October 2, 2001 - ; password settings encrypt passwords ... = yes users = %S [group] comment = %g group share on %L [%U] path = /export/samba/group/%g create mask = 0660 force create mode = 0660 directory mask = 0770 force directory mode = 0770 read only = no browseable = yes force group = %g users ...
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-set-up-a-samba-share-for-a-small-organization-on-ubuntu-16-04
How To Set Up a Samba Share For A Small Organization on Ubuntu 16.04 | DigitalOcean
May 11, 2018 - ... [everyone] path = /samba/everyone browseable = yes read only = no force create mode = 0660 force directory mode = 2770 valid users = @sambashare @admins
๐ŸŒ
Samba
lists.samba.org โ€บ archive โ€บ samba โ€บ 2003-July โ€บ 071130.html
[Samba] "create mask = 0660" and "map archive = yes" ?
July 25, 2003 - Create mask does not give or add ... bit. Maybe what you wanted is "force create mode"?. Force Create mode 0660 would ensure that user and group always get read/write permission to the file....
Top answer
1 of 2
4

Edit the samba configuration file.

sudo nano /etc/samba/smb.conf

Add this to the end of the file:

[Public Directory]
comment = Contents are read/write by all.
path = /home/user/directory-to-be-shared
read only = no
guest ok = yes
create mask = 0666
force create mode = 0666
directory mask = 0777
force directory mode = 0777

Then restart samba.

sudo service smbd restart

Notes:

  1. The string within brackets (Public Directory in the example above) is what users will see when accessing the shared folder from other systems.
  2. Files created within this directory by users on other systems will be owned by nobody:nogroup, with read and write permissions for owner, group, and other.
  3. Directories created in this directory by users on other systems will be owned by nobody:nogroup, with read, write, and directory traversal permissions for owner, group, and other.
  4. The masks and modes in the configuration file apply to files and directories created by users on other systems. These masks and modes are ignored when creating files as a user on the server. Or, to put it another way, if you are user on the server, make sure that each file and directory that you create within /home/user/directory-to-be-shared has 666 and 777 permissions respectively.
  5. If you have enabled a firewall on the server, you will need to open port 445 for tcp. For example, if you use ufw (uncomplicated firewall) to configure the firewall:

    sudo ufw allow in 445/tcp
    sudo ufw reload
    sudo ufw status verbose
    
2 of 2
2

It's not clear to me if you want a share accessible to everyone or only a group of client users so this is a template for the latter.

Note: This will only work as described if the default umask of your system is 0002 so it will not work for Ubuntu Desktop 17/18 but it will work for Xubuntu Desktop and Ubuntu Server.

In this template it is required that all users you want to have access become members of the "users" group. It will assign the setgid bit on the shared directory and any future subdirectories which forces anything new added to them to inherit the group of it's parent folder.

sudo mkdir /path
sudo chown root:users /path
sudo chmod 2775 /path

The share would look like this:

[UsersShare]
path = /path
valid users = @users
force group = users
read only = no
create mask = 0664
force directory mode = 2775

When bob - who was made a member of the "users" group - logs in with his samba username/password and adds a file to the [UsersShare] share it will have owner = bob, group = users, mode = 664 files / 2775 folders.

All other client users who are members of the users group who sign in will have full access to whatever bob did.

Any local users - those on the server itself - who add or modify files who are also members of the users group will all have the same ability and newly created files/folders will have the same 664/2775 mode and all will have as group: "users". The one exception to all this is root - as in when you use sudo - since it's default umask is 022 unlike a regular user his files will inherit the "users" group but will have a mode of 644.

If you truly want a pure public share where everyone has access replace "valid users = @users" with "guest ok = yes". For this to work locally on the server you would still need to add those users to the "users" group.

๐ŸŒ
It's FOSS Community
itsfoss.community โ€บ general linux question
/etc/samba/smb.conf: why exists the "force create mode" and "force directory mode" parameters? - General Linux Question - It's FOSS Community
March 22, 2024 - Hello Friends About Samba I am reading the following valuable tutorial: How to Set Up a Network Shared Folder on Ubuntu With Samba At the Step 2: Configuring Samba section appears the following configuration [sambashare] comment= Network Shared Folder by Samba Server on Ubuntu path = /home/your_username/sambashare force user = smbuser force group = smbgroup create mask = 0664 force create mode = 0664 directory mask = 0775 force directory mode = 0775 public = yes read only = no Observe the ...
๐ŸŒ
Reddit
reddit.com โ€บ r/linux4noobs โ€บ why do files i created in my samba share have the wrong permissions?
r/linux4noobs on Reddit: Why do files I created in my Samba Share have the wrong permissions?
May 25, 2020 -

** SOLVED! **

I failed to understand that the mask set in the "create mask" parameter is fundamentally different than basic file permission modes.

Instead of a create mask of 0770, I should have used 0660.

Thanks u/lutusp

** Original Problem **

When I connect to my //server/public samba share, and I create a new file, that file has the wrong permissions.

Here is my smb.conf file:

[global]                                           
    map to guest = Bad User                                            
    name resolve order = bcast                                         
    workgroup = WORKGROUP                                              
    log file = /var/log/samba/%m                                       
    log level = 1                                                      
                                                                       
[public]                                                               
    path = /smb-shares/public                                          
    create mask = 0770                          # Correct answer was to change this to 0660                       
    force create mode = 660                                            
    directory mask = 2770                                       
    directory mode = 2770                                        
    read only = no                                                     
    guest ok = yes                                                     
    valid users = guest, jesse, derek, owner 

And here are some files I created:

drwxrwsr-x 2 owner public  4096 May 25 11:38 New Folder
-rwxrw---- 1 owner public 0 May 25 11:38 text.txt

The folder has permissions 775, even though I specified 770.

The file has permission 760, even though I specified 660. Why?