Linux change permissions on all folders

Change all files and folders permissions of a directory to 644/755

If someone (@animuson) would be so kind to explain me, why this chmod question is off-topic and all others (14,438 results) here aren’t.

Little late, but this one command will also do the accepted answer in one shot: chmod -R a=r,a+X,u+w /your/path

Good question, doesn’t deserve closing. These should rather be moved to a stackoverflow sub site than closed.

@hugoderhungrige it means go ask it on a Server site like: http://superuser.com 😛 but this question helped me here, thanks.

7 Answers 7

One approach could be using find:

for directories

find /desired_location -type d -print0 | xargs -0 chmod 0755 

for files

find /desired_location -type f -print0 | xargs -0 chmod 0644 

just for someone else like me, this doesn’t work instead try sudo find /your/location -type f -exec chmod 644 <> \; for files and sudo find /your/location -type d -exec chmod 755 <> \; for directories

I ran the original solution and it messed up my permissions on files and directories. watch out! the solution on the comment worked, thanks!

What if I want only the subfolder to be chmod 755 when specifying the desired_location ? Because this also will make the parent folder 755

chmod -R u+rwX,go+rX,go-w /path/to/dir 

to ch ange file mod es -R ecursively by giving:

  • u ser: r ead, w rite and e X ecute permissions,
  • g roup and o ther users: r ead and e X ecute permissions, but not -w rite permission.

Please note that X will make a directory executable, but not a file, unless it’s already searchable/executable.

+X — make a directory or file searchable/executable by everyone if it is already searchable/executable by anyone.

Please check man chmod for more details.

This answer, while neat, does have a problem: a file that is executable before running the command will be executable afterwards. See the answer of @JohnAllsup for a command that does not have this flaw.

The shortest one I could come up with is:

which works on GNU/Linux, and I believe on Posix in general (from my reading of: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/chmod.html).

  1. Set file/directory to r__r__r__ (0444)
  2. Add w for owner, to get rw_r__r__ (0644)
  3. Set execute for all if a directory (0755 for dir, 0644 for file).

Importantly, the step 1 permission clears all execute bits, so step 3 only adds back execute bits for directories (never files). In addition, all three steps happen before a directory is recursed into (so this is not equivalent to e.g.

chmod -R a=r /foo chmod -R u+w /foo chmod -R a+X /foo 

since the a=r removes x from directories, so then chmod can’t recurse into them.)

Источник

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.

Читайте также:  Adobe flash archive linux

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.

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.

Источник

Change permissions on all folders and files

I have ubuntu 12.04. I want to change permissions on all folders and files at the same time so that anyone can modify or remove them.

First, you should file each question separately. Second, could you clarify what your intention is when you say you want to change the permissions of all files and folders? Do you want all files to be user-writeable (which I would advice very strongly against), or do you simply want to share files between different users of the system?

Читайте также:  Настройка postgresql linux ubuntu

It will be useful if you tell us which files and folders are you referring to. Changing the permissions system wide for read/write sounds risky and I don’t think it is a great idea. Please provide more details. Thank you!

2 Answers 2

If you are talking about your home folder or any shared folder then you can chmod -R 777 /Your/folder/path/ . If you just want to make the files read and write enabled then I would set the permissions to 766 instead.

This said, for this to work, your partition entry in the fstab file must permit read/write and execute permissions.

First important point you do not want to change the permissions on all files and folders: changing the permissions on some files can break your system.

Command Line Way

So lets assume instead you want to change the the permissions in all the files in a particular folder and its sub-folders.

I have a folder in my home directory which does not give any access to «others»; this contains a sub-folder sub which also does not give any access to others.

img no access

If I now want to give «others» read access I make sure I am in the correct directory and enter

As you can see the permissions are changed

img with access

If you only want to do this in the current directory omit -R from the command.

If you want to do this in a directory you don’t own you will need to prefix the command with sudo

If the files are owned by you run the file manager if not press ALT + F2

Type gksu nautilus and enter your password when requested.

Hold down the SHIFT key or CTRL key to select the files you want: SHIFT selects all the files in a range CTRL selects one file at a time. Now right click and select properties; in the window that opens you can select the permissions tab and you can set the permissions from there.

Источник

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.

Читайте также:  Linux in ssd raids

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

Источник

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