- Chmod 777 to a folder and all contents [duplicate]
- 7 Answers 7
- You can give permission to folder and all its contents using option -R i.e Recursive permissions.
- Ideally, give 755 permission for security reasons to the web folder.
- What Is chmod 777 and What Does It Do in Linux?
- Permissions in Linux
- What the 777 Means
- The chmod Command
- chmod 777
Chmod 777 to a folder and all contents [duplicate]
I have a web directory /www and a folder in that directory called store . Within store are several files and folders. I want to give the folder store and all files and folders within the store folder all permissions. How do I do this? I am guessing via .htaccess.
You need to seriously think about giving 777 to all files and folders under /www directory, which means all your files and directories will be readable, writable and executable by whole world.
Just to counter the alarmist misinformation in the comments: your files probably won’t be writeable or even likely readable «by the whole world». You’d have to setup a web server that explicitly allowed these things, which would be very uncommon. These files will be readable, writeable, and executable by any user who’s able to login to your system.
@JoshNoe It isn’t alarmist. Read the OWASP top 10 web application security vulnerabilities: A5 is «security misconfiguration» (e.g. 777 on upload directory) and A1 is «injection». A1 + A5 = pwnd. google.com/search?q=nginx+config+php+code+injection+jpg+comment On Linux the web server runs under a user (e.g. www-data) so every time the server serves a file it is a user logged into the system.
@Pocketsand Granting 777 to the user your web server runs under generally won’t open your files to «the whole world». By default, most web servers don’y serve any files by default, until you explicitly set them up to.
@JoshNoe I assume you’re talking about whether directory listings are configured but that is not what is being discussed here. The comments are concerning basic defensive security principles to help prevent things like code injection and directory traversal attacks. What your saying is analogous to «It’s alarmist to say people should lock their doors if their curtains are already shut.»
7 Answers 7
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:
If you need more info about chmod command see: File permission
and if you have a symlink to said folder, to change the permissions on the symlink do chmod -h 777 /some_path/symlink
Note chmod -R 777 /some/path will fail silently if your target is a one of the following file systems: NFTS / exFAT / FAT32
If by all permissions you mean 777
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
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
- 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.
I haven’t downvoted, but I think the reason is that your answer does not cover the OPs question. It’s still a good answer, just not for this topic.
@MarijkeLuttekes: There are already answers who are giving light on how to give 777 permissions to folder. That’s not my intention to answer. I am saying not to give 777 permission to folder at all to www folder. See first comment for question of anubhava. Instead give 755 or required permissions. We understand sometimes from question that OP is heading in wrong direction. Then we should give path should be followed. It’s not only OP will be requiring solution. With same question another person will come to this page for finding answer, then that person will understand what this answer.
This should be marked the correct answer. While the other answers give the ‘solution’ to the problem, this one explains how a typical folder structure should be setup. Very rarely if ever would you want to make a web folder 777. Read the More info links that @SomnathMuluk has provided so that you can understand why.
What Is chmod 777 and What Does It Do in Linux?
This article explores chmod 777, a Linux command used to give ALL RIGHTS to the user, group, and others.
As a new Linux user, web developer, or system administrator, you have probably been instructed to type:
chmod 777 /path/to/file/or/folder
Whenever you’re running commands on your systems (especially as root!), you should ALWAYS know what they’re up to. So what’s chmod 777 really about?
Permissions in Linux
Above is an example of running the:
command, which will list the current directory contents in the long listing format, which shows the permissions and modification dates for the files being listed.
- The first column shown is the permissions assigned to the file or directory
- The second column is the number of files or folders contained
- The third and fourth columns show the user and group who have permissions for those files, respectively
- The fifth and sixth show the size and modification date
- The final column shows the name of the file
The first, third, and fourth columns contain information relevant to permissions, which will be referenced in this article
The folders listed in the screenshot are in the linuxscrew users home directory, and all have the permission
With both the owner and group of the linuxscrew user who owns them.
drwxr-xr-x contains 4 pieces of information, 3 of them regarding permissions:
- The first letter shows what type of file – if it’s d it’s a directory, if it’s – it’s a regular file
- The 2nd-4th characters contain the permissions for the user
- The 5th-7th characters contain the permissions for the group
- The 8th-10th characters contain the permissions for others
The letters in each block have the following meanings:
There are also some special values that the eXecute character can take:
- ‘s’setuid bit, found in the user or group permissions, users able to execute the file will execute with the privileges of the file’s owner and/or the file’s group. It means that x is set, making the file executable
- ‘S’ Same as ‘s’ but the file is not executable
- ‘t’ Sticky bit, found in the others permissions, makes the file sticky – only the owner can rename or delete the file or files within. Group and others cannot! It also means that x is set, making the file executable
- ‘T’ Same as ‘t’ but the file is not executable
For completeness, different file types can occupy the first character space:
- ‘-‘ regular file
- ‘b’ block special file
- ‘c’ character special file
- ‘C’ high performance (“contiguous data”) file
- ‘d’ directory
- ‘D’ door (Solaris 2.5 and up)
- ‘l’ symbolic link
- ‘M’ off-line (“migrated”) file (Cray DMF)
- ‘n’ network special file (HP-UX)
- ‘p’ FIFO (named pipe)
- ‘P’ port (Solaris 10 and up)
- ‘s’ socket
- ‘?’ some other file type
What the 777 Means
To make things quicker to type when assigning permissions, numbers can be used to represent combinations of the letters shown above:
So, to give ALL RIGHTS to both the user, group, and others, we’d want to assign the permission 777
The chmod Command
The chmod (Change Mode) command lets you apply permissions to files.
chmod 777
chmod 777 /path/to/file/or/folder
…will give the file or folders owner (user), group (users within the group), and others (everyone else on the system) full read, write and execute privileges.
chmod -R 777 /path/to/file/or/folder
This will do the same thing, recursively, and give everyone full rights on the files contained within a directory.