Create Directory with Write Permissions for the Group

How to create a directory and give permission in single command

According to mkdir's man page...

mkdir -m 777 dirname

Creating new folders that have read-write access

I believe fullPathFile.getParentFile().setWritable(true) before calling mkdirs() should do.
The method setWritable (bool) is a convenience method to set the owner's write permission for this abstract pathname.
Since is a File, you can apply it.

C program to mkdir in POSIX shared memory missing permissions

You need to set the permission explicitly or reset your file creation mask with the umask() function.

Per the POSIX mkdir() documentation (bolding mine):

The mkdir() function shall create a new directory with name path. The file permission bits of the new directory shall be initialized from mode. These file permission bits of the mode argument shall be modified by the process' file creation mask.

The only thread-safe way to create a file or directory with the exact permissions you want is to explicitly set them after creation:

mkdir("/dev/shm/example", 0777);
chmod("/dev/shm/example", 0777);

Of course, you'd do well to actually check the return values for those calls.

Calling umask() to set and restore your file creation mask is not thread-safe:

mode_t old = umask( 0 );
mkdir("/dev/shm/example", 0777);
umask( old );

There are multiple race conditions possible with doing that:

  • The old mask you get with the first call to umask() can be the 0 set by another thread
  • Either call can overwrite the value of the file creation mask currently in use by another thread

If either of those race conditions happens, either

  • your file/directory won't get the permissions you need
  • the other thread's file/directory won't get the permissions it needs
  • the original file creation mask setting will be lost

Or all three.

So don't call umask() when you need to set permission bits exactly. Set the mode explicitly with a call to [f]chmod()

(The possible issues that could arise from creating directories in /dev/shm is probably worth another question...)

PHP - Cannot to create new folder and new file because linux permission

before proceeding to create the directory try to change the permissions of the project folder to 755 or 777

chmod -R 755 myproject/

if its still not working try it with permission 777

chmod -R 777 myproject/

and also while creating directory with mkdir you should assign permissions simultaneously

mkdir("$directory", 0755);

Why can't HTTP process write into directory with group permissions?

After further research and talking with some SysAdmins, the answer was straight into the groups that apache belongs to.

Regardless of the factor that the directories files by apache had the ec2-user group, didn't mean that apache belonged to that group.

So, to address this specific request, all I had to do, is add Apache to the ec2-user group.

sudo usermod -a -G ec2-user apache

I haven't very well figured out the mac version, but it goes along the ways of using the dseditgroup command.

how can I create a file with file_put_contents that has group write permissions?

You might what to try setting the umask before calling file_put_contents : it will change the default permissions that will be given to the file when it's created.

The other way (better, according to the documentation) is to use chmod to change the permissions, just after the file has been created.



Well, after re-reading the question, I hope I understood it well...

How do I give PHP write access to a directory?

An easy way is to let PHP create the directory itself in the first place.

<?php
$dir = 'myDir';

// create new directory with 744 permissions if it does not exist yet
// owner will be the user/group the PHP script is run under
if ( !file_exists($dir) ) {
mkdir ($dir, 0744);
}

file_put_contents ($dir.'/test.txt', 'Hello File');

This saves you the hassle with permissions.

centos add folder full access only to a specific group

There are a couple of issues with your chgrp command. The ":" character and the 777 parameter are causing the "group not valid lavagrp" error because the chgrp program doesn't understand what these are.

I also wouldn't recommend to set 777 on this folder either. You can achieve the same result using the following commands.

sudo chmod 770 /var/www
sudo chgrp lavagrp /var/www

This means the owner has read, write and execute permissions, the group has read, write and execute permissions and every other user cannot read, write or traverse into that directory.



Related Topics



Leave a reply



Submit