DEV Community

loading...
Cover image for How to set chmod 777 to a folder and all its contents ?

How to set chmod 777 to a folder and all its contents ?

courseprobe profile image Course Probe ・2 min read

In this short tutorial, we are going to evaluate some options to use chmod in directory in a recursive way. Maybe you are running centos or ubuntu, these examples will be a good guide for any linux distribution.

Let’s say you have a folder named profilesand within that folder there are several folders, so if for any reason you need to give or assign full permissions to all the folders, sub folders and files, this is how you can do it.

If you are going for a console command it would be:

chmod -R 777 /www/store. The -R (or --recursive) options make it recursive.

Or if you want to make all the files in the current directory have all permissions type:

chmod -R 777 ./

If you need more info about chmod command see: File permission

You can give permission to folder and all its contents using option -R i.e Recursive permissions.

But I would suggest not to give 777 permission to all folder and it’s all contents. You should give specific permission to each sub-folder in www directory folders.

Ideally, give 755 permission for security reasons to the web folder.

sudo chmod -R 755 /www/store
Enter fullscreen mode Exit fullscreen mode

Each number has meaning in permission. Do not give full permission.

N   Description                      ls   binary    
0   No permissions at all            ---  000
1   Only execute                     --x  001
2   Only write                       -w-  010
3   Write and execute                -wx  011
4   Only read                        r--  100
5   Read and execute                 r-x  101
6   Read and write                   rw-  110
7   Read, write, and execute         rwx  111
Enter fullscreen mode Exit fullscreen mode
  • First Number 7 — Read, write, and execute for the user.

  • Second Number 5 — Read and execute for the group.

  • Third Number 5 — Read and execute for others.

If your production web folder has multiple users, then you can set permissions and user groups accordingly.

Interesting resources:

Get the book: Devops engineer

source: https://stackoverflow.com/questions/8328481/chmod-777-to-a-folder-and-all-contents


Other Dev posts:

Discussion (0)

pic
Editor guide