1

On my local dev machine my nginx server runs as user www-data. I have a separate 3TB HDD which stores my local websites. The HDD is mounted automatically on Ubuntu 16.04 startup. I can access my files properly with my own user, but when I su www-data and try to access the files that way I get a permissions error when accessing anything mounted in the /media/ folder.

How can I allow www-data to access this hard drive?

Details: BLKID (last HDD)

sudo blkid
/dev/sda1: UUID="BB84-E577" TYPE="vfat" PARTUUID="d62d7f99-f050-4411-8e57-0030bbd73635"
/dev/sda2: UUID="aba7016b-3277-416b-9243-fc10f1752b12" TYPE="ext2" PARTUUID="d567afcf-1f63-4f53-a8a9-d61c619f9493"
/dev/sda3: UUID="r3Gnc3-zpe7-m81D-dBde-ShtM-6z0j-FZhaIG" TYPE="LVM2_member" PARTUUID="d4ffe4c2-0c4e-45bd-83fe-3d12d5b4a74b"
/dev/sdb1: PARTLABEL="Microsoft reserved partition" PARTUUID="ff6c7bf2-9ffa-4d27-aebd-8f4f9569b985"
/dev/mapper/ubuntu--vg-root: UUID="fd4ff318-8e5c-489e-a17c-08a6c02f7919" TYPE="ext4"
/dev/mapper/ubuntu--vg-swap_1: UUID="86e3d28e-3c13-4e5d-a8c1-ad56778355e7" TYPE="swap"
/dev/sdb2: LABEL="data" UUID="53c5e897-b414-4faf-892c-ffd415f4d451" TYPE="ext4" PARTLABEL="Basic data partition" PARTUUID="30eff523-5ebc-46f5-9051-2e6604cb772d"

Details: FSTAB

/dev/mapper/ubuntu--vg-root /               ext4    errors=remount-ro 0       1

# /boot was on /dev/sda2 during installation
UUID=aba7016b-3277-416b-9243-fc10f1752b12 /boot           ext2    defaults        0       2

# /boot/efi was on /dev/sda1 during installation
UUID=BB84-E577  /boot/efi       vfat    umask=0077      0       1
/dev/mapper/ubuntu--vg-swap_1 none            swap    sw              0       0


/dev/disk/by-uuid/53c5e897-b414-4faf-892c-ffd415f4d451 /media/steven/data auto nosuid,nodev,nofail 0 0
  • Which group owns the HDD, add www-data to that group. – George Udosen Dec 22 '17 at 11:02
  • run ls -ald /path/to/hdd to find the group that owns that device! – George Udosen Dec 22 '17 at 11:07
  • ls -ald /dev/sdb2 results in: brw-rw---- 1 root disk 8, 18 Dec 21 16:28 /dev/sdb2 – stevenmc Dec 22 '17 at 14:59
  • Add www-data to disk group and lets see: sudo usermod -a -G disk www-data – George Udosen Dec 22 '17 at 15:29
  • Great let me post an answer then, cheers! – George Udosen Dec 22 '17 at 19:18
1

Two things I would suggest:

  1. Find which group owns that device:

    ls -ald /dev/sdX
    
    • where X is the letter representing the external drive usually /dev/sdb, or /dev/sdc
  2. Add www-data user to that group:

    sudo usermod -a -G disk www-data
    

And now user www-data should be able to access that external HDD.

  • 1
    I'll be able to use this answer for a problem I was having with Plex Media Server too (changing www-data to plex). Thanks George. – stevenmc Dec 23 '17 at 15:45

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.