I cant get samba to set proper permissions on created directories

649

Solution 1

I think you need to use the following parameters:

# I changes the permissions to rw-rw-r--
# You should be able to change them to 775 if you need the files to
# be executable
create mask = 664
force create mode = 664
security mask = 664
force security mode = 664

# I set the SGID flag here as I thought this is what you wanted
# You could change to 0775
directory mask = 2775
force directory mode = 2775
directory security mask = 2775
force directory security mode = 2775

I was looking for a nice explanation of how these settings work, but could not find anything better then man smb.conf

You will have to scroll down a bit for those options.

Basically, in a nutshell, windows permissions are not the same as unix (linux) and it is a bit odd how samba maps permissions.

Solution 2

I had the same problem, but everything like mask directives did not work for me (Samba 4.3.11):

 create mask = 0664
 force create mode = 0664
 directory mask = 02775
 force directory mode = 02775

The only option that worked was under the [global] or share section:

 inherit permissions = yes

Just change all folder and file permissions to your need, so future folders and files will inherit the same permissions.

Solution 3

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.

I have group named 'admin' set as primary group to users with write privileges, everyone else gets read only rights.

I force user to nobody, so different people working on same files don't interfere with each other.

I set chmod 2755 on shared directory, so it inherits created directories with the same group 'admin'

$ chmod -R 2755 /home/shares/test

Checking if all is good:

$ stat /home/shares/test
Access: (2755/drwxr-sr-x)  Uid: (65534/  nobody)   Gid: ( 1001/   admin)

Relevant part of /etc/samba/smb.conf:

[test]
        comment = test
        path = /home/shares/test
        force user = nobody
        read only = No
        create mask = 0664
        force create mode = 0664
        directory mask = 02775
        force directory mode = 02775

This post put me on right track, but testparm revealed 4 incorrect directives, so I'm sharing fixed config here. In samba, the less directives you specify the better it works.

Solution 4

There is a very similar problem when connecting from other Unix / Linux / OSX / MacOS devices: all of the settings are ignored unless you specify

[global]

unix extensions = no

And connect with smb://<serverhost> instead of cifs://<serverhost>.

Share:
649

Related videos on Youtube

Anton Safonov
Author by

Anton Safonov

Updated on September 18, 2022

Comments

  • Anton Safonov
    Anton Safonov over 1 year

    I have a problem. If I set clearFocus() in setOnItemClickListener it's not work. Focus set nearby input. How I can clear focus in autocomplete, after I clicked item?

    textView.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    arrAuto = (String) ((TextView) view
                            .findViewById(R.id.item_auto)).getText();
                    findViewById(R.id.editText1).clearFocus(); //it's not work
                }
            });
    
    • waqaslam
      waqaslam about 12 years
      why dont you set focus to any other view after clicking...?
    • Anton Safonov
      Anton Safonov about 12 years
      I just do not like this solution
    • Anton Safonov
      Anton Safonov about 12 years
      OK, may be anybody knows how clear focus after start app? I want if app started - all inputs don't have focus.
    • Anton Safonov
      Anton Safonov about 12 years
      OK, I now simple hide keyboard, question for focus closed.
  • Zaz
    Zaz over 12 years
    Yes, that seems to be roughly the same manpage as samba.org/samba/docs/man/manpages-3/smb.conf.5.html which I looked at, the problem is that it doesn't seem to matter what octal values I set, I still get the same permissions set on the created file or folder.
  • Panther
    Panther over 12 years
    Did you set all the options I gave you ? If so, please update your first post and at that point I would suggest you file a bug report.
  • Zaz
    Zaz over 12 years
    It already said.. but on closer inspection and testing, adding the 2 to the directory masks did fix the problem. Many thanks. : D
  • Panther
    Panther over 12 years
    Fantastic, thank you for marking this as the accepted answer, it help others with a similar problem.
  • Matthias Hryniszak
    Matthias Hryniszak about 8 years
    Samba configuration is overly complex and really hard to understand. For example what is the logical difference between force create and just create... makes no sense. Your hint is a life saver though - thank you!
  • Andi S.
    Andi S. almost 6 years
    I am using Samba version 4.7.6-Ubuntu. And this is working for me too.
  • jitter
    jitter almost 5 years
    true answer for 4.8.11 on freebsd, too :)
  • Merritt
    Merritt over 4 years
    Simple and perfect on 18.04.3
  • Admin
    Admin about 2 years
    I tried this, and as a result, all my files were created with the executable flag being set. this does not make sense in 99.9% of all cases I see.