Jump to content
StevenOliver

Directory not writeable even though chown and chmod

Recommended Posts

Posted (edited)

On Ubuntu 20.04, I've done this a hundred times and it's always worked fine:
chown -R www-data:www-data /var/www/html
usermod -aG www-data My_User_Name

Today, when trying to write a file in html, I get a "Directory '.' is not writeable" error.

All the directories are 755, all the files are 644, and I've verified I'm a member of www-data.

What am I missing, please?

Thank you.

p.s. I know I can do "chown -R MyUserName:MyUserName /var/www/html" and then I can write to the directory... but I'm trying to figure out why on earth the above suddenly won't work.
 

Edited by StevenOliver

Share this post


Link to post
Share on other sites

Can you tell me what the permissions 755 mean?

Share this post


Link to post
Share on other sites
Posted (edited)

755 means: Owner can read, write, execute. Everyone else can read, execute.
When I stat my d and f:
755 drwxr-xr-x    www-data www-data    Aug  5 20:18 www
755 drwxr-xr-x www-data www-data Aug  5 20:19 html
644 -rw-r--r-- www-data www-data Aug  1 18:12 index.html

... and check if I'm a member of www-data....
$ groups //command line
My_User_Name sudo www-data // result

So, www-data owns the files. And, I'm a member of www-data. As a member of www-data, I should also be able to write. What am I missing?

Edited by StevenOliver

Share this post


Link to post
Share on other sites
7 hours ago, StevenOliver said:

755 means: Owner can read, write, execute. Everyone else can read, execute.

That's right: owner can write, everybody else cannot.

 

7 hours ago, StevenOliver said:

So, www-data owns the files. And, I'm a member of www-data. As a member of www-data, I should also be able to write. What am I missing?

www-data is the owner. Are you www-data?

Share this post


Link to post
Share on other sites

But I am a member of the www-group. I thought that was the point of "becoming a member." Would you please explain what is the point of being a member of the www-data group if I do not inherit its privileges?

Share this post


Link to post
Share on other sites

You did inherit the privileges of the www-data group. But the permissions you applied to allow writing are not for the www-data group. They are for the owner of the directory, and in this case the owner of the directory is www-data the user.

There is a user named "www-data" and there is a user group named "www-data". They are two separate (but related) things.

Share this post


Link to post
Share on other sites

Unfortunately, I have google searched this exact thing, and found too many conflicting "solutions." Each "solution" proposes a line of code, followed by, "well, this worked for me...". And, I don't want to mislearn yet another "hack." Rather, I'd like to know the correct way to do this.

So here is a properly worded question:

For a sudo user to create files in the /var/www/html directory of an Apache2/Ubuntu 20.04 cofiguration, what are the "best practices" lines of chmod and chown code to accomplish this?

Thank you

Share this post


Link to post
Share on other sites

A "sudo user" doesn't make sense. sudo is a tool that lets you run commands as another user - typically root.

Forget for a moment what you are trying to do. Why are you trying to do it? What is fiddling with permissions supposed to solve?

Share this post


Link to post
Share on other sites

Next time try StackOverflow. They don't mind giving you the right answers to the wrong questions.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.