5

I want to change permissions + owner on a .htaccess file but how do I go about doing this? I have tried googling it but most answers are just for people looking to do it on a directory recursively.

I'm sitting in the directory where the .htaccess is.

httpdocs/downloader/

I login to the user I want the owner to be:

chown -R root .

then does this change the owner + permissions?

chmod 644 .htaccess

Thank you.

Using Ubuntu 12.04.5 LTS.

3
  • 4
    Possible duplicate of Change folder permissions and ownership
    – MadMike
    Mar 23, 2017 at 12:22
  • @MadMike I don't believe that question is a duplicate, specially since OP says: but most answers are just for people looking to do it on a directory recursively. I know the answers are similar, but to someone new, they can't know the difference if it wasn't explained to them
    – Dan
    Mar 23, 2017 at 12:29
  • @Dan The first answer on the linked question specifically address the usage of recursively changing the folder content or a single file. So that's why I marked it as a duplicate.
    – MadMike
    Mar 23, 2017 at 12:31

1 Answer 1

7

To change ownership and/or access of a file, do:

sudo chown <user>:<group> /path/to/file
sudo chmod <owner><group><everuone> /path/to/file

Using -R when modifying permissions for single file is unnecessary (recursive changes make sense when you modify directories).

A change to your .htaccess file's ownership and permissions can be made like this:

#go to the folder where the file is located
cd /var/www/mywebsite
#change ownership to the desired user and group
sudo chown wwdata:wwdata .htaccess
#change permissions
sudo chmod 644 .htaccess
#verify
ls -lah .htaccess
1
  • 3
    If you are the owner of the file, you do not need sudo to use chmod on the file. Mar 23, 2017 at 14:29

You must log in to answer this question.

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