Question

I am creating a folder to have my website in it. How do I add permission to create this folder?

MKDIR 777 MyWebSite

Will give Rear, Write & eXecute access to everyone.

So what is the best set of permission that i should use when creating this folder ?

Était-ce utile?

La solution 2

For a web document root, the best permissions are 755 for directories/folders & 644 for files. The key is making sure the directories/folders as well as the files are owned by the same user connected to the web server. Which in Linux systems is usually www-data. I actually gave a fairly detailed explanation on why 777 permissions are not good for any reason over here and here is an edited version for your question.

When you set permissions to 777 it means that 100% anyone with access to your machine on any level can read, write & execute the file. Meaning if your site gets hacked, a hacker than then use the execute permissions to launch scripts to get deeper in your system. Or someone else on the system—since they can read, write & execute the file—can simply delete your files without you ever knowing.

Setting directories to 755 and setting files to 644 is the best way to go as long as the ownership of the file is solid & correct. 644 permissions basically break down as follows:

  • The first 6 means the owner of the file can read & write to it.
  • The next 4 means members of the group connected to that file can only read it.
  • The next 4 means others—who are neither the owner or a member of the group—can read it.

As for 755 they are best for directories/folders because directories/folders need to have execute rights to allow you to view the contents inside of them. So it breaks down like this:

  • The first 7 means the owner of the file can read, write & execute it.
  • The next 5 means members of the group connected to that directory/folder can only read & execute it.
  • The next 5 means others—who are neither the owner or a member of the group—can can only read & execute it.

Autres conseils

Best is 755 for everything (dirs) 644 for files. Some directories (like uploads in WordPress) need to have 777 as any user can send file there. But that BIG permission should be set only for such directory not for everything. Normally READ for files and execute for dirs (with read) would be enought for almost any directory and file (only that upload dirs needs more).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top