LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-16-2013, 12:23 PM   #1
Dornith
Member
 
Registered: Jul 2012
Location: U.S.A
Distribution: Archlinux Multilib, Debian 7.0.0 32b
Posts: 153

Rep: Reputation: Disabled
Make new files in a directory use pre-defined permissions


I created a group called web-server that has permission to manage files that are displayed by a web server. Is there a way to cause any file created in /srv/http/ to use these permissions?
Code:
-rw-rw-r-- 1 [user] web-server
 
Old 11-16-2013, 07:44 PM   #2
jdackle
Member
 
Registered: Apr 2010
Distribution: Debian, LMDE
Posts: 46

Rep: Reputation: 11
My reply bwlow is somewhat vague but I hope it will give you the necessary pointers for you to proceed to an effective sollution.
It's basically a two-part process: 1) setting default group ownership and 2) setting default permissions.

1) For having all new files and directories to be created on your /srv/http be given the group-belonging web-server:
Code:
chgrp web-server /srv/http
chmod g+s /srv/http
2) Concerning the default permissions for new files and directories, I guess the traditional way would be for you to go through umask[1].

Were your "/srv/http" directory be in an unlikely FAT partition, you could mount it:
a) if a partition in itself:
Code:
mount [device] /srv/http -o umask=002
b) if a folder inside an already mounted partition:
Code:
mount --bind /srv/http/ /srv/http/
mount -o remount,umask=002 /srv/http
However, the FAT family of filesystems is rather outdated and it's unlikely you'll have them in any modern setup. You can still use umask though, but not as an option to mount, rather as the command itself.The line:
Code:
umask 002
will set the subsequent creations of files and directories to that umask.
Hence, you could place that command in /etc/profile or /etc/bashrc to have them set for all users (or use ~/.profile or ~/.bashrc for each concerning user).
However, this would affect all operations in all directories, not only in your /srv/http! It may or may not be what you want...
Also do note that any concerning user would be able to change that behaviour during their sessions.

[1]: umask=002 sets default directory permissions to 775 (rwxrwxr-x) and file permissions to 664 (rw-rw-r--). For an excelent article on umask check: http://www.cyberciti.biz/tips/unders...lue-usage.html

Finally, on another thread here at the forums, someone asked a very similar question and there were mentions of alternatives to what I said above. You might want to check it out: http://www.linuxquestions.org/questi...ectory-831340/

Last edited by jdackle; 11-18-2013 at 05:22 AM. Reason: ERRATA: Line 2 on my first code-block had "web-server" (the users group) instead of "/srv/http" (the directory to setgid)
 
  


Reply

Tags
directory, file, group, permissions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Changing permissions for new files, but only for one directory tlb944 Linux - Security 2 10-03-2013 09:07 PM
[SOLVED] How to create a file of pre-defined size in C ? Aquarius_Girl Programming 7 02-18-2010 04:33 AM
Linux Installation with pre-defined passwd sineri Linux - Newbie 1 06-06-2009 09:45 AM
Inserting Date and Other Pre-defined Strings In Evolution cmnorton Linux - Software 0 10-16-2008 01:23 PM
permissions question... can I make a directory writable from my user account hindenbergbaby Linux - Newbie 9 10-20-2003 04:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration