0

I have a network drive that is available via a Samba share. I want to create, edit, read/write files on that shared drive from Windows 10 and from Ubuntu mate.

I noticed that when I created a file from Linux I could not edit it from Windows. Also, when I rsync'd a lot of files from Windows (NTFS) to the shared drive (ext4) I could view them but not edit them from Ubuntu. The command I used was...

sudo rsync -rltzhHvn --info=progress2 "/media/ubuntu-mate/DATA/Personal Stuff" "/media/ubuntu-mate/4TB1/DataShare/Personal-Stuff"

I understand a bit about Linux permissions and Samba so this is a solution I'm thinking of using...

  1. Create an Ubuntu user account (ubuntu-user) that does not have root access. Only use sudo on rare occasions I really need to.
  2. Files that are created in Ubuntu will have owner/group like --> ubuntu-user:ubuntu-user
  3. I will configure the Samba share like..
force user = ubuntu-user
create mask = 0666
directory mask = 0777
  1. Now Windows should be able to edit/delete files that were created in Ubuntu and also create files that can be edited/deleted in Ubuntu.

Do I have it right or is there a better way?

For instance what if file is created by some system process or maybe root in Ubuntu then I won't be able to read/write/edit it via the share from Windows? In this case I know that I could change the Samba share to...

force user = root
create mask = 0666
directory mask = 0777

And I think that will work but now any files created from Windows won't be editable by the Linux ubuntu-user. I could just do force user = root in the Samba share and create a Linux user account with root access which would be easier but I think not advisable.

Cheers.

1 Answer 1

2

These are my permissions but I would suggest creating a sambauser and sambagroup. The force user and force group will take care of the created files permissions.

   path = /path/to/file
   force user = sambauser
   force group = smbagroup
   create mask = 0664
   force create mode = 0664
   directory mask = 0775
   force directory mode = 0775
   public = yes
   writable = yes

Note: The way I have this setup would be for a private network the permissions allow anyone to modify the files if you want have files that can be shared but not modified I would recommend a separate folder with more restrictive permissions on it.

Hope this helps, Jason C.

5
  • Thank you. I understand: The force user and force group will take care of the created files permissions. But can you explain why I need sambauserand sambagroup? How does Windows OS read, write files and list directories from the share if it didn't create them and doesn't have read/write permissions on the file? force user = root overcomes that problem but then files it creates are root:root which is not good practice is it? Do sambauserand sambagroupneed to have the same name as the user I log in as in the Linux OS? Commented Feb 22, 2021 at 1:40
  • 1
    You technically don't need to make the sambauser and sambagroup and if this is just on your home network for your personal use you don't have to but it would be best practice. I am going to leave a link here that has a great wiki and video i think will give you everything your looking for wiki.learnlinux.tv/index.php/… Commented Feb 22, 2021 at 1:46
  • Thanks so much for the link. So I understand that if you change the Owner:Group of ALL files and directories in a shared drive and give write access to the Group then force group will let my Windows OS write files in that share from a Windows File Explorer. BUT what if my Linux OS comes along and then creates a file in that share? Can Windows edit that file? Oh.. will the Linux created file have the same Owner:Group as if created in Windows because Windows and Linux OS are both writing to the Samba share in a way that both are forced to create/edit files as the same Owner:Group. Is that it? Commented Feb 22, 2021 at 2:04
  • 1
    Yes as long as the writeable = yes is set. If this is just for you then you can leave it like that but anyone you has access to the share can modify or delete files if you change the writeable = no then they (Windows) would only be able to view them not change them. Commented Feb 22, 2021 at 2:15
  • I see. So Samba requires a share to be Samba Writeable AND for the file to have OS file system write-access permission before you can write to it. But I don't see why you would go to all the trouble above with force this and that in a share definition and then say writeable = no. Maybe that link is just doing it that way to demonstrate the read-only feature in Samba by way of contrast. Commented Feb 22, 2021 at 2:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.