5

It appears that after upgrading to 16.04 I constantly have problem with share folder ownership and permission.

I created a folder name test, changes its permission to 777, and shared that folder in local network.

From another machine (Windows), I can view and edit file on that test folder, but whenever I edit something on a file in that folder, the ownership and permission change to nobody:nogroup - and therefore I cannot edit it again on my 16.04 machine.

test$ ll
total 328
drwxrwxrwx 2 pac   pac      4096 Jan 20 09:59 ./
drwxrwxrwx 4 pac   pac      4096 Jan 20 09:32 ../
**-rwxr--r-- 1 nobody nogroup** 326442 Jan 20 09:59 t1.log*

Why does it automatically change to -rwxr--r-- 1 nobody nogroup? How can I prevent this change so that the permission is always rwxrwxrwx and ownership is always pac:pac (removing that nobody:nogroup annoyance)?

I want to avoid having to do this repeatedly on the folder test:

$ sudo chown pac:pac . -R
$ chmod 777 . -R
  • See here and here to see if these help – George Udosen Jan 19 '17 at 23:18
  • @George thanks, will give a try. Strange is that these all happen on 16.04, before I did not have any issue using 14.04 – artm Jan 19 '17 at 23:21
  • @artm, I'm a little bit surprised that this worked for you in 14.04. Samba users and system users are two different things. The same goes for file and directory permissions. With Samba you can configure file and dir permissions per share. See here : samba.org/samba/docs/man/Samba-HOWTO-Collection/… help.ubuntu.com/lts/serverguide/… (create mask part). – albert j Jan 19 '17 at 23:30
  • @albertj I actually use Nautilus to "Share this folder" and set permissions via "Properties > Permission" option on folder test to have "Read and write" for "Others". I did the same before on 14.04 and can edit files freely on both machines. It worked very simple that way, but now it doesn;t on 16.04 – artm Jan 19 '17 at 23:35
  • 1
    Aha. Did it work for you now ? Good. – albert j Jan 19 '17 at 23:48
3

This is an issue relating to file and directory permissions when working with samba and not 16.04. I assume you are setting up a public share and not using logins, and mapping the samba guest user to the user nobody.

Since all samba users will be logged in as nobody, any file saved will inherit the user nobody and group nogroup.

Your file t1.log that is created by the samba guest user has the permissions -rwxr--r--, and the owner of that file is nobody. Your user pac is not able to modify it as it has only read permission for Others.

One way to resolve this is to remap the samba guest user to your user pac.

Make sure this is set in your /etc/samba/smb.conf:

guest account = pac

...then change the ownership for all the files in your share folder to user pac

sudo chown -R pac:pac /path/to/share

_

Obviously this won't work in a multiuser environment where some other user other than pac needs rw access too.

Some may propose the use of create mask = 0777 and directory mask = 0777 in smb.conf for files and directories to be created with -rwxrwxrwx, however in my experience I have found it to be quite unreliable, as over time some files still ended up with some other permissions anyway.

The only reliable solution I have found is to remount the share directory with bindfs to always force 0777 permissions.

First, install bindfs:

sudo apt install bindfs

Then, create a systemd service file:

sudo nano /lib/systemd/system/mount-bindfs.service

Paste this in the file:

# mount-bindfs systemd service file

[Unit]
Description=Remount directories with different permission
After=mountall.service

[Service]
Type=forking
ExecStart=/bin/sh -c "/usr/bin/bindfs -o perms=0777 /path/to/share /path/to/share"

[Install]
WantedBy=multi-user.target

Reload systemd, enable the service on boot and start it:

sudo systemctl daemon-reload
sudo systemctl enable mount-bindfs.service
sudo systemctl start mount-bindfs.service

Do a ll on your share folder and everything should appear as rwxrwxrwx now.

| improve this answer | |
  • Adapted from here – loongyh Jan 20 '17 at 1:16
  • You can also define -o perms=0777,user=pac,group=pac if you want to force ownership on the files too. – loongyh Jan 20 '17 at 1:26
2

In case of permission problems with Samba shares, it is good to realize that Samba has its own structure for users, as well as file and dir permissions. If one creates a Samba share, and one wants to restrict access by giving only certain users access to that Samba share, one would normally create Samba users. On the command-line this can be done with the command "smbpasswd". See for more info :

man smbpasswd

To add user and file/dir permissions to the Samba configuration, one can edit the smb.conf file located in /etc/samba/

See also here :

https://help.ubuntu.com/community/Samba/SambaServerGuide#Samba_Server_Configuration_in_terminal

and for setting permissions, see here :

https://help.ubuntu.com/community/Samba/SambaServerGuide#File_Sharing_.28Advanced.29

After editing smb.conf, the Samba server daemons need to be restarted or the reading in of the config file needs to be done (reload).

In some older Ubuntu versions, one could restart both smbd and nmbd, but in newer Ubuntu versions, the "init" script samba can be restarted.

sudo service samba restart

In some office environments it can make sense to only do a config reload, instead of a Samba restart, to avoid possible interruptions for the users.

/etc/init.d/nmbd force-reload && /etc/init.d/smbd force-reload

This is on some older Ubuntu releases. I assume on newer Ubuntu releases :

sudo service samba force-reload 

might work.(Have not tested this yet).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.