Permissions – Fix “chmod g+w” Not Working on NAS in Ubuntu 16.04.4 LTS

14.04chmodfstabmountpermissions

Background

I am a passionate PLEX Media Server ("PMS") user. I was running both PMS and uTorrent on a Mac Mini in my bedroom. uTorrent downloaded media from the internet to a 2Tb WDMyCloud NAS ("NAS") on my home LAN and PMS would stream media from the NAS to clients both on my home LAN and on the internet. It all worked really well.

I wanted to reduce noise, add additional storage space and arrange things so as to have a lighter energy footprint (a Raspberry PI 3 wasn't enough). So I recycled an older (but not yet old) i5 SONY Vaio laptop (the "SONY") and a 1.5Tb USB hard drive.

So now I am using:

  1. The SONY running snappy Ubuntu Core 16.04.4 LTS, fully updated and upgraded as at March 2nd, 2018, as follows:

    stefano@SONY:/$ uname -a
    Linux SONY 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    

It runs headless, without any GUI. I ssh into it as needed through my wired LAN (no wifi).

  1. My 2Tb WDMyCloud NAS, running Debian as follows:

    WDMyCloud:/dev# uname -a
    Linux WDMyCloud 3.2.26 #1 SMP Thu Jul 9 11:14:15 PDT 2015 wd-2.4-rel armv7l GNU/Linux
    
  2. My even older 1.5Tb USB hard drive which shows as "Story_1_5Tb_2" ("STORY"). It is plugged into the NAS, which consequently shows as follows:

    WDMyCloud:/dev# lsblk -f        
    NAME    FSTYPE            LABEL       MOUNTPOINT
    sda                                   
    |-sda1  linux_raid_member             
    | `-md1 ext3                          /
    |-sda2  linux_raid_member             
    | `-md1 ext3                          /
    |-sda3  swap                          [SWAP]
    |-sda4  ext4                          /DataVolume
    |-sda5                                
    |-sda6                                
    |-sda7                                
    `-sda8                                
    sdb                                   
    `-sdb1  ntfs              Story 1.5Tb /var/media/Story_1_5Tb_2
    

Current situation

On the SONY the following users exist:

stefano@SONY:/home/plex$ cut -d: -f1 /etc/passwd
root
daemon
[...]
nobody
[...]
stefano
plex
debian-transmission

These users have been added to the group mediaserver.

stefano@SONY:/home/plex$ getent group mediaserver | awk -F: '{print $4}'
stefano,plex,debian-transmission,daemon,nobody

The storage natively on the NAS (WDMyDrive) and the 1.5Tb USB hard drive (Story_1_5Tb_2) have been mounted as follows:

stefano@SONY:/home/plex$ ls -l
total 0
drwxr-xr-x 2 plex mediaserver 0 Mar  2 12:00 story
drwxr-xr-x 2 plex mediaserver 0 Mar  2 10:50 WDMyCloud

stefano@SONY:/home/plex$ ls -l story
total 0
drwxr-xr-x 2 plex mediaserver 0 Mar  1 13:40 Shared [A]
drwxr-xr-x 2 plex mediaserver 0 Mar  1 13:40 Shared [B]
drwxr-xr-x 2 plex mediaserver 0 Feb 25 23:02 System Volume Information
-rwxr-xr-x 1 plex mediaserver 0 Feb 28 06:49 temp.ts
drwxr-xr-x 2 plex mediaserver 0 Mar  2 09:49 Shared [C]
drwxr-xr-x 2 plex mediaserver 0 Mar  1 18:19 Shared [D]

stefano@SONY:/home/plex$ ls -l WDMyCloud
total 0
drwxr-xr-x 2 plex mediaserver 0 Feb 24 09:19 Shared [E]
drwxr-xr-x 2 plex mediaserver 0 Feb 21 12:32 Shared [F]
drwxr-xr-x 2 plex mediaserver 0 Feb 21 12:29 Shared [G]
drwxr-xr-x 2 plex mediaserver 0 Nov 20  2016 Shared [H]
[other shares]

The /etc/fstab of the SONY looks as follows:

  GNU nano 2.5.3              File: /etc/fstab                                  

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sdb1 during installation
UUID=6e54f9e7-5579-437b-9e7d-5f76b3fe146e /               ext4    errors=remount-ro 0       1
# swap was on /dev/sdb5 during installation
UUID=59f57e49-82e9-4be3-b53a-1a65c0e771ae none            swap    sw              0       0


# These are the mounts needed to let PLEX find the media shared in WDMyCloud and Story_1.5Tb
#
//WDMyCloud/Public /home/plex/WDMyCloud cifs _netdev,uid=plex,gid=mediaserver,rw,guest 0
#
//WDMyCloud/Story_1_5Tb_2 /home/plex/story cifs _netdev,uid=plex,gid=mediaserver,rw,guest 0
  • I assigned ownership of the shares to uid=plex so that PMS would be allowed to operate on the NAS and on the STORY
  • I allowed gid=mediaserver so that stefano,plex,debian-transmission,daemon,nobody would also be allowed to operate
  • Same reason behind the choice to specify rw (read & write) as an mount option

The WDMyCloud share (mounted in /home/plex/WDMyCloud) corresponds to a Public folder on the NAS, as follows:

WDMyCloud:/DataVolume/shares# ls -l
total 32
drwxrwxrwx+ 12 root share 4096 Mar  2 10:50 Public
drwxrwxrwx+  2 root share 4096 Mar  8  2017 SmartWare
drwxrwxrwx+  2 root share 4096 Mar  2 10:39 Stefano
lrwxrwxrwx   1 root share    24 Mar  2 10:43 Story_1_5Tb_2 -> /var/media/Story_1_5Tb_2
drwxrwxrwx+  2 root share 4096 Mar  8  2017 TimeMachineBackup

What works

  1. Light like a feather, Ubuntu core flies like a rocket on my 4-yo SONY i5.
  2. Running on an OS deprived of all is not needed, PMS transcodes and streams like a charm. It seamlessly recognized the network shares (both the NAS and the STORY) and is able to operate on them. When needed, it is able to move, add and delete files, no matter where I access its web interface from.
  3. Network is also great and PMS streams to the internet and outside my home LAN.
  4. Transmission installed, the daemon starts upon boot and the web interface is accessible: from the web interface I can load torrents and magnet-links. As I load them, Transmission accesses the internet and attempts to download.

Great, but…

What doesn't work

Somehow I was unable to let Transmission write on the STORY.

…so:

  1. Trasmission's daemon launches
  2. the web interface is accessible from within the home LAN (no need to open other doors on my router, for the time being) and
  3. I can add torrents, but…

…torrents will NOT download, because of a "Permission denied".

Apparently, user debian-transmission (I assume he is the guy) is not allowed to write on the STORY.

What I tried

  1. chmod Symbolic –> to no avail

    plex@SONY:/home/plex$ ls -l
    total 0
    drwxr-xr-x 2 plex mediaserver 0 Mar  2 12:00 story
    drwxr-xr-x 2 plex mediaserver 0 Mar  2 10:50 WDMyCloud
    
    plex@SONY:/home/plex$ ls -l /home/plex/story
    total 0
    drwxr-xr-x 2 plex mediaserver 0 Mar  1 13:40 Shared [A]
    drwxr-xr-x 2 plex mediaserver 0 Mar  1 13:40 Shared [B]
    drwxr-xr-x 2 plex mediaserver 0 Feb 25 23:02 System Volume Information
    -rwxr-xr-x 1 plex mediaserver 0 Feb 28 06:49 temp.ts
    drwxr-xr-x 2 plex mediaserver 0 Mar  2 09:49 Shared [C]
    drwxr-xr-x 2 plex mediaserver 0 Mar  1 18:19 Shared [D]
    
    plex@SONY:/home/plex$ sudo chmod -R g+w /home/plex/story
    [sudo] password for plex: 
    
    plex@SONY:/home/plex$ ls -l
    total 0
    drwxr-xr-x 2 plex mediaserver 0 Mar  2 12:00 story
    drwxr-xr-x 2 plex mediaserver 0 Mar  2 10:50 WDMyCloud
    
    plex@SONY:/home/plex$ ls -l /home/plex/story
    total 0
    drwxr-xr-x 2 plex mediaserver 0 Mar  1 13:40 Shared [A]
    drwxr-xr-x 2 plex mediaserver 0 Mar  1 13:40 Shared [B]
    drwxr-xr-x 2 plex mediaserver 0 Feb 25 23:02 System Volume Information
    -rwxr-xr-x 1 plex mediaserver 0 Feb 28 06:49 temp.ts
    drwxr-xr-x 2 plex mediaserver 0 Mar  2 09:49 Shared [C]
    drwxr-xr-x 2 plex mediaserver 0 Mar  1 18:19 Shared [D]
    
  2. chmod Absolute –> to no avail

    plex@SONY:/home/plex$ sudo chmod -R 0770 /home/plex/story
    
    plex@SONY:/home/plex$ ls -l
    total 0
    drwxr-xr-x 2 plex mediaserver 0 Mar  2 12:00 story
    drwxr-xr-x 2 plex mediaserver 0 Mar  2 10:50 WDMyCloud
    
  3. I even tried to set Setuid – I thought maybe if Transmission can read and execute a file on the STORY it could also write and delete it if the file is given owner's privileges. It was a long shot and of course… it did not work.

    plex@SONY:/home/plex$ sudo chmod -R u+s /home/plex/story
    
    plex@SONY:/home/plex$ ls -l
    total 0
    drwxr-xr-x 2 plex mediaserver 0 Mar  2 12:00 story
    drwxr-xr-x 2 plex mediaserver 0 Mar  2 10:50 WDMyCloud
    
  4. Then I read that it could be the ntfs file system of the STORY mounted with cifs. As I learned, apparently Linux can usually only read from ntfs file systems and ntfs-3g is required.

Another long shot, because either I can write on a ntfs file system or not. In my case uid=plex can write, but the members of gid=mediaserver cannot: this is odd.

But I removed the Story_1_5Tb_2 line from /etc/fstab and tried ntfs-3g –> to no avail.

plex@SONY:/home/plex/story$ sudo ntfs-3g //WDMyCloud/Story_1_5Tb_2 /home/plex/story
[sudo] password for plex: 
ntfs-3g: Failed to access volume '//WDMyCloud/Story_1_5Tb_2': No such file or directory

ntfs-3g 2015.3.14AR.1 integrated FUSE 28 - Third Generation NTFS Driver
        Configuration type 7, XATTRS are on, POSIX ACLS are on

Copyright (C) 2005-2007 Yura Pakhuchiy
Copyright (C) 2006-2009 Szabolcs Szakacsits
Copyright (C) 2007-2015 Jean-Pierre Andre
Copyright (C) 2009 Erik Larsson

Usage:    ntfs-3g [-o option[,...]] <device|image_file> <mount_point>

Options:  ro (read-only mount), windows_names, uid=, gid=,
          umask=, fmask=, dmask=, streams_interface=.
          Please see the details in the manual (type: man ntfs-3g).

Example: ntfs-3g /dev/sda1 /mnt/windows

News, support and information:  http://tuxera.com

Since the location has not changed, maybe rtfs-3g does not recognize network mounts?

Why is chmod not working? …and why is mounting with -o gid=mediaserver,rw not working either?

The STORY drive is a USB hard drive, ntfs formatted and plugged into the NAS. I can access it and uid=plex as its owner has it all: read, execute and write. Everything is connected within a wired (cabled, not wifi) LAN. I really need to be able to allow Transmission ("uid=debian-transmission") to write on the STORY drive.

The thing is that uTorrent installed on the Mac Mini in my bedroom can still access the STORY – why not Transmission on the SONY? What am I doing wrong?

Best Answer

I changed my etc/fstab so that it would mount the network share as follows:

//WDMyCloud/Story_1_5Tb_2 /home/plex/story cifs _netdev,guest,uid=plex,gid=mediaserver,rw,iocharset=utf8,file_mode=0770,dir_mode=0770 0 0

In particular, I added the following options to the string:

,iocharset=utf8,file_mode=0770,dir_mode=0770,

This gave full read, write and execute permissions on the network share to the members of "uid=mediaserver" group. "Uid=plex" already had all such permission even prior to the modifications; I chose to grant no permission to "o"ther users at all.

Now if I ls -l the folder where I mounted my STORY I get:

drwxrwx--- 2 plex mediaserver 0 Mar 3 09:53 story

Consequently, Transmission (member of the "uid=mediaserver" group) saves its downloads alright: happy ending!

Now, whereas I see what those options do (the "absolute" values are identical to chmod, which makes the whole thing pretty much self-explanatory), I do not understand why what I did earlier (setting uid and gid) was not enough/correct, nor do I understand why executing chmod with sudo privileges would do nothing to solve the issue. Actually the similarity of this option to chmode makes it look like some sort of chmod executed upon mount, so why would a chmod executed later not solve?

Related Question