Glam Prestige Journal

Bright entertainment trends with youth appeal.

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
8

2 Answers

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 :

and for setting permissions, see here :

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).

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.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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