saiid
saiid

Reputation: 613

SSH Change ownership of public_html

The default ownership for public_html was myusername:nobody

drwxr-xr--. 18 myusername nobody       4096 Jun  1 16:06 public_html/

I changed this to myusername:myusername since I need to access a file inside public_html using the following command

# chown myusername:myusername public_html

It worked and ownership changed.

Now I'm not able to change the ownership back to myusername:nobody. I'm using this command

chown livegiftcard:nobody public_html

and it gives me the error

chown: changing ownership of âpublic_htmlâ: Operation not permitted

I have also tested this with sudo and also chgrp but no luck.

Also I could not run my website. Browser gives me the following error.

Forbidden

You don't have permission to access / on this server. Server unable to read htaccess file, denying access to be safe

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request

Upvotes: 0

Views: 2209

Answers (1)

Dentastic
Dentastic

Reputation: 101

Problem: The apache/nginx has a user, who needs to read the files in the Docroot. Default user and group is: www-data:www-data. I'm not user if this is correct in your case.

Now the files are owned by myusername:myusername and the apache/nginx user is probably not in the the group "myusername". So if you have some knowledge about the permission system of linux, the webserver user have only the rights everybody have (third column). When the group was set to nobody, the files weren't owned by any group and every user can act under the group permissions. In your case I guess the group can read all files and all other can't.

What you can do: Give all others the right to read the files with

chmod -R o+r public_html

Now everybody, including the webserver user can read the files and you will not get the 403 error. -R is for recursive, so every file and directory under public_html will get the readable flag too.

Another thing is to add the webserver user to the group "myusername" so the webserveruser can use the group permissions too.

The third and last possibility which came to my mind is to change the group to "nogroup" instead of "nobody" because nobody is the user and nogroup the group.

Upvotes: 2

Related Questions