1

Hi just installed Apache2 on Ubuntu 20.04. Added myself to www-data group. id prateek

uid=1000(prateek) gid=1000(prateek) groups=1000(prateek),4(adm),24(cdrom),27(sudo),30(dip),33(www-data),46(plugdev),120(lpadmin),131(lxd),132(sambashare)

changed the ownership and permission of /var/www/bihag.moops/public_html.

ls -l /var/www/bihag.moops/ 
total 4 
drwxrwxr-x 3 www-data www-data 4096 Aug 11 07:58 public_html

Folders inside public_html also belongs to the same group.

ls -l /var/www/bihag.moops/public_html/
total 8
-rwxrwxr-x 1 www-data www-data  191 Aug 11 07:54 index.html
drwxrwxr-x 2 www-data www-data 4096 Aug 11 07:59 logs

Still can't write to public_html. Even though I am the member of the same group. Why this discrimination?

touch home.php
touch: cannot touch 'home.php': Permission denied

Note: Even though this is a local machine. I don't want to use 777 permission.

Additionally:

lsattr /var/www/
--------------e----- /var/www/bihag.moops
--------------e----- /var/www/html

And

lsattr /var/
--------------e----- /var/mail
--------------e----- /var/log
--------------e----- /var/www
GunJack
  • 361
  • 2
  • 5
  • 19
  • If I become the owner of public_html how will it be possible for the webserver to write anything in there? – GunJack Aug 11 '20 at 03:20
  • https://github.com/waltinator/pathlld will help you explore this problem. – waltinator Aug 11 '20 at 03:48
  • I think you need to use *setgid bit* as it is shown here: [Fixing permission settings on html folder](https://askubuntu.com/a/1164046/566421). Another kind of solution is to remount the directory at another mount point with different owner by using *bindfs*, as it is shown here: [Setting up SFTP to log in to server with Filezilla](https://askubuntu.com/a/1024308/566421). – pa4080 Aug 11 '20 at 04:10
  • Thanks that did it. I also changed the ownership of public html to myself. You should write this as an answer, so I could help others too. – GunJack Aug 11 '20 at 05:08
  • 2
    Does this answer your question? [Fixing permission settings on html folder](https://askubuntu.com/questions/1163995/fixing-permission-settings-on-html-folder) – pa4080 Aug 11 '20 at 06:14
  • 1
    Hi, GunJack. I'm glad to hear your problem is solved. Instead of duplicating the answer I've marked the question as possible duplication. If you want you could up-vote the related answer in order to tell the others it is useful. – pa4080 Aug 11 '20 at 06:16

1 Answers1

0

You might want to check on the extended attributes of /var/www (and its subdirectories), like so:

$ lsattr /var/www # or /var/www/bihag.moops, or /var/www/bihag.moops/public_html

If the i (immutable) attribute is set, e.g. you see something like:

----i--------------- /var/www

then that could explain why you cannot create a new file in the directory even with the right permissions. In that case, you could remove the i attribute by doing:

$ sudo chattr -i /var/www # or /var/www/bihag.moops, or /var/www/bihag.moops/public_html
  • No immutable attribute. It has an e attribute. I will update my question to reflect the output of these commands. – GunJack Aug 11 '20 at 04:57