Linux permission to create file in directory

Setting default permissions for newly created files and sub-directories under a directory in Linux?

I have a bunch of long-running scripts and applications that are storing output results in a directory shared amongst a few users. I would like a way to make sure that every file and directory created under this shared directory automatically had u=rwxg=rwxo=r permissions. I know that I could use umask 006 at the head off my various scripts, but I don’t like that approach as many users write their own scripts and may forget to set the umask themselves. I really just want the filesystem to set newly created files and directories with a certain permission if it is in a certain folder. Is this at all possible? Update: I think it can be done with POSIX ACLs, using the Default ACL functionality, but it’s all a bit over my head at the moment. If anybody can explain how to use Default ACLs it would probably answer this question nicely.

POSIX ACLs are nice, however a good 60% of the machines that you encounter won’t have them turned on for certain file systems, depending on the distribution. Here is a very good introduction and example: suse.de/~agruen/acl/linux-acls/online

You mean the same document I linked 🙂 I haven’t had a change to read it yet but thanks for the head’s up on the availability problem.

The link in Tim Post’s comment appears to be dead, but thanks to the Internet Archive, I could view it, and verify that vanemery.com/Linux/ACL/POSIX_ACL_on_Linux.html contains the exact same document. I’ll edit the question to update the link.

Источник

What is the proper permission to a directory while creating a file in it

However I get an error: permission denied.
I know that I should chmod for the directory but I don’t know what a proper permission is because I don’t want to make it 777.
Also, I should chmod for each directory like this:

sudo chmod . a cd a sudo chmod . b cd b sudo chmod . c . 

2 Answers 2

You need a minimum of ‘execute’ permissions on directories a/ , a/b/ , and a/b/c/ , with ‘write’ permission on directory a/b/c/d/ . The execute permission allows you to traverse the directory to get to the next one, you don’t need actual write permissions on the intermediate directories. You can use the recursive option to chmod to grant execute permissions:

Читайте также:  Android sdk linux path

Do keep in mind that this command will affect all files and all directories within a/ , not just the directories you mention.

Use +X (uppercase X) instead to only set the x bit on directories, and to files that already have it.

example suppose user p1 wants to create a file in /a/b/c/d/

Only Owner and Group have read,write and execute permission but user p1 not in Group list and owner.

At that you time you have 2 options change others permission like below

chmod o+rwx /path_whereyou_want_to_create_file/ means all the users will be having rwx permission so they will be able to create a file.

But for safer side You can acl permission like below so it will give read, write,execute permission only to particular user and path

setfacl -m u:p1:rwx /path_whereyou_want_to_create_file/

Источник

What are permissions to create a folder or file?

I’ve seen lots of stuff on the internet about HOW to set permissions. Please tell me WHAT permissions are required for a user to be able to create a folder or a file. I would have thought just w but I’m not sure.

The only permissions are read, write, and execute. What is the actual problem that you are trying to solve? It’s better to ask about the actual problem and provide details and context than ask a coded/vague question that won’t actually help you solve the problem.

small addition: the directory -above- where you want to make a dir or file needs to be rwx for your user and/or your group and/or others depending on the user used to create it.

Читайте также:  Java jdk linux debian

2 Answers 2

To change file and directory permissions change directories with cd to the directory that contains the file/directory whose permissions you want to change, and use the command chmod (change mode).

Add write permissions to a file or a directory:

chmod +w filename chmod +w directoryname 

If you want to read the file and also want write permissions, you need read permissions too. Add read/write permissions to a file or a directory:

chmod +rw filename chmod +rw directoryname 

In Linux (and all Unix-like operating systems), there’s the principle that «everything is a file». That includes, among other things, directories. A directory is basically a file that contains information about the contents of the directory.

So if you have, for example, the directory /home/kristy/some_files/ and want to create a new file (or a new subfolder) in this directory, you need to write to the file representing this directory. And in order to do that, you need write permissions on this directory.

Thanks for your responses. Apparently I was right: the user needs w. The permissions on my folder are: drw-rw-rw- 2 www-data www-data 4096 Dec 20 20:05 tmp Yet when I try to write a file to it from a php called shell_exec command I get this: [Errno 13] Permission denied: ‘/var/www/tmp/TestTopics.txt’ How can I make the www-data user able to write a file to /var/www/tmp ?

Sorry, this forum is very restrictive. The permissions on the folder: /var/www/tmp are drw-rw-rw- 2 www-data www-data 4096 Dec 20 20:05 tmp I’m trying to create/write a file to the tmp folder in Python from a php shell_exec command. I’m getting this error in Python: [Errno 13] Permission denied: ‘/var/www/tmp/TestTopics.txt’ How can I make the www-data user able to create a file in /var/www/tmp ?

@kristy1024 This isn’t a forum, I’m afraid. You may want to look at the tour to find out how this site is intended to be used. Regarding your (new) question, write permission on the directory should allow any user that has this permission to create a new file in the directory. If the file already exists, you need to look at the file’s permissions. Also check that your programs or scripts actually are running as www-data , that’s not necessarily the case. The details may depend on how exactly you have set up your system.

Читайте также:  Adding crontab in linux

Источник

Create file in folder: permission denied

I have a problem copying files to a directory on Ubuntu 12.04. I create a directory in the home directory so that the path where I want to copy to is:

francisco-vergara@Francisco-Vergara:/home/sixven/camp_sms/inputs$ touch test_file.txt touch: can not make `touch' on «test_file.txt»: permission denied 

I can not copy files directly in that directory. How can I assign permissions with the chown & chmod commands to copy the files? I do not know which user and group to use.

From what you have copy-pasted, you are running touch as user francisco-vergara , but your directory is in /home/sixven is that really the home of user francisco-vergera or does it belong to a sixven user ? You should clarify what you want to do exactly. Write in another user’s home ? Share that directory among a group ?

3 Answers 3

First of all you have to know that the default permission of directories in Ubuntu is 644 which means you can’t create a file in a directory you are not the owner.

you are trying as user:francisco-vergara to create a file in a directory /home/sixven/camp_sms/inputs which is owned by user:sixven .

So how to solve this:

    You can either change the permission of the directory and enable others to create files inside.

sudo chmod -R 777 /home/sixven/camp_sms/inputs 
sudo chown -R francisco-vergara:francisco-vergara /home/sixven/camp_sms/inputs 

So i advise you to use Option 1.

Or if this directory will be accessed by both users you can do the following trick:

change ownership of the directory to user:francisco-vergara and keep the group owner group:sixven .

sudo chown -R francisco-vergara /home/sixven/camp_sms/inputs 

Like that both users can still use the directory.

But as I said you before It’s easiest and more efficient to use option 1.

Источник

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