0

I am making 3 sites in Drupal and need to frequently change the settings.php file in each website folder. This file is read-only for security reasons by default, so before I can edit it, I use:

chmod a+w settings.php

I make my changes, and then harden permissions again:

chmod go-w settings.php

This usually works and results in the file permissions looking like this:

-r--r--r--

However, I noticed in one of my Drupal sites, when I use chmod go-w settings.php it instead changes to

-rw-r--r--

and I am still able to modify it as the owner of the file.

The files are essentially identical and in identical folder structures and even the same ancestor directory, but my command to harden permissions is resulting in a different set of permissions. Why is my chmod command affecting these two files differently, and how do I force -r-r--r-- permissions?

Additional Info

  • Using MacOS terminal on Ventura 13.4.1
  • Before I know about the chmod command, I attempted to use sudo vim settings.php to edit the file which didn't work. Not sure if this might have affected the permissions somehow.

Edit: I'm adding this edit to not mislead anyone looking at this in the future. My understanding about how the change permissions command works was wrong. As per the answers to my question, the resulting permissions -r--r--r-- are actually what was incorrect, not -rw--r--r--.

2
  • so, it's the -r--r--r-- that's wrong Jul 13, 2023 at 14:26
  • chmod a+w followed by chmod go-w shouldn't result in -r--r--r-- in any case, as you're adding write permission to everyone, but removing it only from the group and others. Anyway, if you want to remove all write permissions, why not just use a-w instead of go-w?
    – ilkkachu
    Jul 13, 2023 at 14:43

1 Answer 1

1
  • chmod a+w settings.php adds write permission to user/group/other (if it's not already present). Typically this will lead to rw?rw?rw? permissions, where ? could be - or x
  • chmod go-w settings.php removes write permission from group/other (if it was present). Running this after the previous command will lead to rw?r-?r-?, where ? can represent - or x and are unchanged from before

You'll hopefully see that although the first command added write permission for the file owner, i.e. you, the second does not remove it. If you usually end up with r--r--r-- permission after having applied both of these commands then something else has removed the write permission for the file owner.

1
  • Thanks for the correction. I will update my question to not mislead anyone with my misunderstanding. What is strange is that after using chmod go-w settings.php vim would warn me that the file is read-only again despite me being the owner. I noticed this isn't working any longer today which lead me to discovering this issue. I will have to dig into this to understand what is happening better. Jul 13, 2023 at 14:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .