Windows – How to create a Samba share that is writable from Windows without 777 permissions

chmodpermissionssambashared-folderswindows

I have a path on a Linux machine (Debian 8) which I want to share with Samba 4 to Windows computers (Win7 and 8 in a domain). In my smb.conf I did the following:

[myshare]
path = /path/to/share
writeable = yes
browseable = yes
guest ok = yes
public = yes

I have perfect read access from Windows. But in order to have write access, I need to do chmod -R 777 /path/to/share in order to be able to write to it from Windows.

What I want is write access from Windows after I provide the Linux credentials of the Linux owner of /path/to/share.

I already tried:

[myshare]
path = /path/to/share
writeable = yes
browseable = yes

Then Windows asks for credentials, but no matter what I enter, it's always denied.

What is the correct way to gain write access to Samba shares from a Windows domain computer without granting 777 permissions?

Best Answer

I recommend to create a dedicated user for that share and specify it in force user(see docs).

Create a user (shareuser for example) and set the owner of everything in the share folder to that user:

adduser --system shareuser
chown -R shareuser /path/to/share

Then add force user and permission mask settings in smb.conf:

[myshare]
path = /path/to/share
writeable = yes
browseable = yes
public = yes
create mask = 0644
directory mask = 0755
force user = shareuser

Note that guest ok is a synonym for public.

Related Question