After hours of searching, I discovered that the share name and the share directory cannot be the same (and it's not case-sensitive, either). See this post on serverfault.

So, if I change my share name in smb.conf from:

[Music]

to

[Tunes]

I can both read and write to the share. No other changes to my smb.conf were necessary, and no need to chmod 0777.

Answer from the_meter413 on askubuntu.com
🌐
Reddit
reddit.com › r/linux4noobs › samba permissions mess - can't write anything (from windows)
r/linux4noobs on Reddit: Samba permissions mess - can't write anything (from Windows)
March 3, 2022 -

Hello,

I have a game server running on my machine, and I often move files and folders around.

So I decided to use samba (version 4.7.6-Ubuntu) to create a shared folder (which contains the game server) - and I can't write anything.

The folder is located at /home/locale/Documents.

locale is the username of the account I use to log physically on my machine, and is pretty much the "admin" account. (Note : they don't have root privileges, I'm not that dumb)

To connect to that folder, I use another account, named John. (The username of my Windows account).

I can connect to the share from Windows without any trouble, using the credentials from John (inputing the Unix password) ; but I cannot write anything.

This is what I have in my smb.conf for the folder :

[gameserver]
   path = /home/locale/Documents/
   valid users = John
   browsable = yes
   read only = no
   writeable = yes
   available = yes
   create mask = 0775
   force user = John

I've seen plenty of people on the internet using 644 or 755 as a create mask - I don't want that. The directories set in locale/Documents are all set at 775, and I don't want to change that.

drwxrwxr-x  5 locale locale 4096 mars   3 09:19 .
drwxr-xr-x 19 locale locale 4096 mars   3 09:27 ..
drwxrwxr-x 19 locale locale 4096 mars   1 23:53 gameserver

John is of course part of the locale group. So I should not be a problem to write in the folder right ? After all, it works like that for my FTP.

What I should do ? I am really forced to go full on 777 on my folder in order to make this thing work ?

Thanks.

🌐
Server Fault
serverfault.com › questions › 1061189 › problems-with-read-write-in-samba-share-between-2-computers
ubuntu - problems with read/write in samba share between 2 computers - Server Fault
[sambashare] comment = Samba on Ubuntu path = /mnt/sharedfolder read only = no writeable = Yes browsable = yes create mask = 0777 force create mode = 0777 directory mask = 0777 force directory mode = 0777
🌐
Stack Exchange
unix.stackexchange.com › questions › 701039 › cant-make-samba-share-writable
debian - Can't make samba share writable - Unix & Linux Stack Exchange
May 1, 2022 - security = user is a global setting and cannot be in the share definition. (See man smb.conf and notice that the definition has (G) after it rather than (S), showing it much be in the global section ... This awnser solves the problem in case you can mount your share properly with an user/passwd pair and you are able to read the content of the share from a remote client, but you can't write into the share. Of course you need a section in your /etc/samba/smb.conf like this:
Top answer
1 of 1
1

From your comment:

I forgot to mention that the drive in /media/USBHDD/shares is formatted in NTFS, to be readable on windows. That makes it unable to be changed using chown and chmod, which are both solutions that I've already tried.

I guess you're using ntfs-3g. In this case you should research the following mount options of it: uid,gid,dmask,fmask. First thing you should do is passing uid=MYUSERNAME to whatever mechanism mounts the drive. This will make the filesystem appear as if everything in it belonged to MYUSERNAME.

If you were mounting via fstab, the proper line would look similar to the one in this question (but read my answer there). The path /media/… suggests the drive might be mounted by some sort of automounter; if so, then you should configure its options.

Some parts of my original answer (below) apply to filesystems that support UNIX permissions. With NTFS, instead of chown you should just pass proper uid and gid while mounting.


Original answer:

Your share and objects under it are owned by root and only the owner has write permissions. I'm talking about UNIX permissions in ls -l output, this itself has nothing to do with Samba.

Then Samba forces any valid user (valid users = backups MYUSERNAME root; these are Samba users, not necessarily UNIX users) to be MYUSERNAME (force user = MYUSERNAME) in context of UNIX permissions. This user has no write access.

Possible solutions:

  • let MYUSERNAME own everything in the share:

    sudo chown -R MYUSERNAME: /media/USBHDD/share
    
  • give every user write access to everything in the share:

    sudo chmod -R +w /media/USBHDD/share
    
  • a combination of above, with reduced scope maybe; or a solution that uses group access; now you know what the issue is, so ask yourself what permissions to what asset you want to give to whom.

  • force user = root (if possible), but this would be stupid.

Some of these solutions will work better with different create mask and directory mask in Samba configuration. Research and understand their meaning.

Find elsewhere
Top answer
1 of 1
5

Looks like you created a folder miguel in the media and you have taken ownership of it. Instead, let's create a group, add users to that group, and set the permissions.

sudo groupadd -g 10000 [samba_group]
sudo adduser migeul [samba_group]
sudo chown root:[samba_group] -R /media/migeul
sudo chgrp [samba_group] /media/migeul
sudo chmod 775 -R /media/migeul

This will create a group and attach it to the folder to be shared. You add the users to that group for access. Set the permissions to 775 which gives the owner and the group read-write-execute access while others only read. Set's it recursively.

Verify that you have total access to the folder. With samba, setting the permissions are a little bit different than file permissions with a ubuntu user. What I mean is that verify the permissions after you take ownership because they could result in a samba error later on down the road. Where nobody can access the drive.

Create a samba account that matches your Linux username precisely.

sudo smbpasswd -a miguel
sudo smbpasswd -e migeul

That will prompt you to create a password for the username miguel. Please note that this is only for SMB shares not for the user in the Operating System.

Afterward, open up the samba config and when sharing the drive make sure you type in writable = yes, browsable = yes, read only = no and add your group to it as well. Also, verify the location you are sharing from. Use the place that it is mounted to.

[migeul]
comment = Migeuls folder
​path = /media/migeul
​browsable = yes
​writable = yes
​guest ok = no
​read only = no
​valid users = @[samba_group]

After you reconfig the /etc/samba/smb.conf file, reload it.

sudo smbd reload

These pages go more in-depth with setting up samba shares.

https://help.ubuntu.com/community/Samba/SambaServerGuide https://www.techrepublic.com/article/how-to-set-up-samba-shares-for-groups/

You may also need to set your umask as well. To do that open up /etc/profile using sudo nano /etc/profile and at the bottom type in umask 002. Use Control+O to save and Control+X to exit. Best to reboot the server using sudo reboot and the new mask permissions will take place. That setting re-asserts the same permissions for the users.

🌐
Ubuntu Forums
ubuntuforums.org › showthread.php
Cannot write to SMB from Windows 10
March 10, 2017 - A help and support forum for Ubuntu Linux.
🌐
Server Fault
serverfault.com › questions › 272765 › cant-write-to-samba-share-from-ubuntu
Can't write to Samba Share from Ubuntu - Server Fault
January 15, 2012 - I have a Windows share mounted on Ubuntu 10. I've tried mounting it as smbfs & cifs. I can connect & see data on that share when I use either one. The mount point for Samba is /backup. If I create a file, say using vi, directly in /backup, it saves just fine. However, if I try to create a file in /backup using mysqldump or copy a folder using cp, it fails, saying "cannot create regular file...(name of file it is trying to create)...no such file or directory."
🌐
TrueNAS Community
truenas.com › forums › archives › freenas (legacy software releases) › freenas help & support › sharing
Can't write to SMB share from Ubuntu | TrueNAS Community
March 18, 2022 - @Decoy256 You can ignore that error message and just type in the ip of your NAS, followed by the user creds when prompted. See below. It's true that in recent Kubuntu versions, and other kde distros, dolphin uses it's kio plugins for connection and mounting remote filesystems. Performance can be slower than using a linux kernel CIFS mount.
🌐
Server Fault
serverfault.com › questions › 267747 › ubuntu-cannot-write-to-samba-share
windows 7 - Ubuntu - Cannot write to samba share - Server Fault
May 9, 2011 - # See smb.conf(5) and /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/speed.html # for details # You may want to add the following on a Linux system: # SO_RCVBUF=8192 SO_SNDBUF=8192 # socket options = TCP_NODELAY # The following parameter is useful only if you have the linpopup package # installed.
🌐
Ask Ubuntu
askubuntu.com › questions › 1114214 › cannot-write-to-pi-samba-server-ubuntu-18-04-1
Cannot write to Pi Samba Server Ubuntu 18.04.1 - Ask Ubuntu
January 30, 2019 - [homes] comment = Home Directories browseable = no read only = no create mask = 0775 directory mask = 0775 valid users = %S [User3] create mask = 0775 directory mask = 0775 comment = User3's Storage path = /home/shares/public/User3 valid users = User3 read only = no writeable = yes [User2] create mask = 0775 directory mask = 0775 comment = User2's Storage path = /home/shares/public/User2 valid users = User2 read only = no writeable = yes [User1] create mask = 0775 directory mask = 0775 comment = User1's Storage path = /home/shares/public/User1 valid users = User1 writeable = yes read only = no