Score:0

Make Symlink to folder on USB stick to be owned by www-data group

ng flag

I have a website hosted locally on an Apache2 at my Ubuntu machine, (Kubuntu 20.04). There are some audio files on a folder at a USB stick at the path /media/MyUserName/KINGSTON/audio while the public web folder that I want to create the Symlink on it is /home/MyUserName/www/site/web

In other words, I want to create a symlink to audio at web.

I have tried:

# on /home/MyUserName/www/site/web ...

ln -s /media/MyUserName/KINGSTON/audio audio

The symbolic link has been created successfully. However, the audio folder is not accessible by the web server, so I have tried to change the group of the symlink at the web folder to be www-data by:

sudo chgrp www-data audio

However, I got the following error:

chgrp: changing group of 'audio': Operation not permitted

I also tried to execute the chgrp from the USB stick path @ /media/MyUserName/KINGSTON but I got the same error.

How could I make this symlink accessible by the web server? or How to change its group?

Update

Yesterday I used the following command to mount the USB stick to a local directory and then creating the Symlink to that local directory. It worked fine and I could able to allow Apache access to that directory. However, after restarting today, the issue returned to its original state.

sudo mount -t vfat -o rw,uid=www-data,gid=www-data /dev/sdc1 /home/MyUserName/kingstone

Also today the usb stick becomes /dev/sdb1 instead of /dev/sdc1. So I had to modify it in the command above.

Now the question is: How could I mount that USB stick automatically to /home/MyUserName/kingstone?

in flag
Two questions: (1) What file system is being used on the USB stick? (2) Is AppArmor configured to allow Apache access to the USB stick (despite the symlink)?
ng flag
The USB stick is FAT32. I don't know what's AppArmor. @matigo
sudodus avatar
jp flag
When used by Linux, FAT32 and other Microsoft file systems can only set ownership and permissions for the drive, all directories and files when mounted. This is different from Linux file systems. Please consider using `ext4`, which is a standard Linux file system, where you can control ownership and permissions individually.
sudodus avatar
jp flag
Identify the file system on the USB stick by its **UUID** and use that for mounitng. If you want to mount it always at boot, it is best to add a line for it in the file `/etc/fstab`. The same mount options as with the `mount` commands can be used. Otherwise if you want to decide when to mount, you can create a shellscript with the long mount command line, and run it (which is convenient, if the shellscript name is short).
ng flag
@sudodus Great and it could be the ideal answer. However, but there are some entry's keys I don't know how to configure them for the USB Stick, such as options, dump, pass.
Score:1
jp flag

See man fstab and your current file /etc/fstab for more details.

The first field is where to use

UUID=...

The second field describes the mountpoint

The third field describes the filesystem

The fourth field is where to put the options, separated by commas, corresponding to your mount command line

rw,uid=www-data,gid=www-data

The fifth field for an external drive (your USB stick) can contain a zero: 0

The sixth field for an external drive (your USB stick) can contain a zero: 0 but if you want it to be checked regularly, you can put 2 there (and use tune2fs to set the checking interval if an ext4 file system).

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.