Linux give all permissions to directory

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.»

Читайте также:  Zabbix мониторинг smart linux

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.

Читайте также:  What is search domain in linux

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.

Источник

Change folder permissions and ownership

I would like the user to have full rights on this folder (as well as all sub-directories and files in it):

currently owned by root. I have found numerous posts (in this forum and elsewhere) on how to do this for files but I can’t find a way to do it for whole folders.

9 Answers 9

Use chown to change ownership and chmod to change rights.

As Paweł Karpiński said, use the -R option to apply the rights for all files inside of a directory too.

Note that both these commands just work for directories too. The -R option makes them also change the permissions for all files and directories inside of the directory.

sudo chown -R username:group directory 

will change ownership (both user and group) of all files and directories inside of directory and directory itself.

sudo chown username:group directory 

will only change the permission of the folder directory but will leave the files and folders inside the directory alone.

As enzotib mentioned, you need to use sudo to change the ownership from root to yourself.

Note that if you use chown : (Note the left-out group), it will use the default group for that user.

Читайте также:  Astra linux создать файл команда

If you want to change only the group, you can use:

BEWARE of recursively taking ownership of ANY directory. Think before you leap. Don’t be chown copypastin’ from the internet, kids. Just because you want to install a node package and it won’t let you, don’t sudo chown -R just because the fist hit from googling the error message says to. Reckless sudo chown -R -ing can kill your OS.

It needs to be said that using the -R option only applies to files and folders that exist in the directory already. It does NOT apply to future creations. For example, if you create another folder or file as root within the folder you’ve already changed permissions on, you will have the same experiences you’re having now until you chmod\chown them again.

Make the current user own everything inside the folder (and the folder itself):

very helpful for newbies (like me) when don’t know what to type in ‘usergroup’ for sudo chown : -R /.blabla

If you prefer, this can be done with a GUI as well. You will need to open Nautilus as root to do so. Press Alt + F2 to access the «Run Applications» dialog and enter gksu nautilus

Next, browse to and right click on the folder you would like to modify. Then, select «Properties» from the context menu. You can now select the user or group that you would like to be the «Owner» of the folder as well as the permissions you would like to grant them. Finally, press «Apply Permissions to Enclosed Files» to apply the changes recursively.

Though it seems this does not always work for some operations in a deep folder tree. If it does not work use the appropriate terminal command.

Источник

Оцените статью
Adblock
detector