LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-11-2014, 07:34 AM   #1
leamassiot
Member
 
Registered: Dec 2005
Location: France
Distribution: Debian
Posts: 123

Rep: Reputation: 17
Force owner, owner group, permissions...


Force owner, owner group, permissions at file and directory creation in a given directory

Hello and thank you for reading my post,

I have an application which automatically copies files and directories
from a directory "Ds" to another one "Dt".

Below is what I would like to do:
when a file "F" is copied from "Ds" to "Dt",
I would like to:
- force its owner to "user1",
- force its owner group to "group1",
- force the file access rights to 660 (rw- rw- ---).

when a directory "D" is copied from "Ds" to "Dt",
I would like to:
- force its owner to "user1",
- force its owner group to "group1",
- force the directory access rights to 770 (rwx rwx ---).

Is this even possible (only for the files and directories that will end up in "Dt")?

(Similarly, I know that, with "Samba3" and for a given share, one can set the "force group", "create mask", "directory mask", etc. options to respectively force the owner group of the new files and directories and their access rights.)

Does the "setfacl" command permit this? How?

If not how should I proceed?

Thank you for your help.

--
OS: Debian GNU/Linux 7.2 (wheezy)
"/home" partition mounted with ACL support.
 
Old 03-11-2014, 01:48 PM   #2
notKlaatu
Senior Member
 
Registered: Sep 2010
Location: Lawrence, New Zealand
Distribution: Slackware
Posts: 1,077

Rep: Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732
The `install` command allows you to copy files and directories PLUS set their attributes, so that is how I would do it.

Another option, I guess, would be to set a umask (kind of like you would in your Samba config) but I think that would be less flexible, since it's not a command but a configuration option.

I would look into `install`. The man page is pretty clear on how to set each attribute; use -m for setting mode and -o for setting owner.
 
Old 03-12-2014, 03:29 AM   #3
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
rsync is your friend.

try it with rsync -aviS that should do the trick.
 
Old 03-12-2014, 04:59 AM   #4
leamassiot
Member
 
Registered: Dec 2005
Location: France
Distribution: Debian
Posts: 123

Original Poster
Rep: Reputation: 17
In reply to notKlaatu:

Hello and thank you for your answer.

The "install" command you mentioned is interesting.

I tried:

Code:
root# install -o user1 -g group1 -m 660 <file_src> <file_dest>
where <file_src> was an already existing file with owner and owner group "root" and permissions "644".

As a result to this command execution, the file <file_dest> was indeed created with owner "user1", owner group "group1" and permissions "660".

Yet, I see two drawbacks in this method which do not suit my needs:
1) there has to be a source file and a destination file when I would want only one file...
2) a command has to be run which I would like to avoid (if possible). That's why, with the "Samba3" setting parallel I alluded to in my first post, I was thinking about the possibility of a specific setting on the directory which contains <file_src> ; a setting which would force the owner, owner group and permissions of all the newly created files...

Best regards.
 
Old 03-12-2014, 05:03 AM   #5
leamassiot
Member
 
Registered: Dec 2005
Location: France
Distribution: Debian
Posts: 123

Original Poster
Rep: Reputation: 17
In reply to lleb:

Quote:
rsync is your friend.
try it with rsync -aviS that should do the trick.
Thank you for your answer.

Can you elaborate a bit on this "rsync" command because I don't see what to do?
Running "rsync -aviS" as is only returns an error.

Best regards.
 
Old 03-12-2014, 01:07 PM   #6
notKlaatu
Senior Member
 
Registered: Sep 2010
Location: Lawrence, New Zealand
Distribution: Slackware
Posts: 1,077

Rep: Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732
Then you are looking to set attributes on the filesystem.

So, in Samba you are configuring the shared directory and setting a umask for the directories. On many Linux filesystems, you can do this with `setfacl`. I have never had the occasion to be this granular so you'll need to read the man page or an online tutorial to learn more about it, but that is probably what you are looking for. You want to set a mask on directory 'Dt' such that anything written into it has specific attributes; that's done with ACL's via `setfacl`.

Good luck!
 
Old 03-12-2014, 01:30 PM   #7
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by leamassiot View Post
In reply to lleb:



Thank you for your answer.

Can you elaborate a bit on this "rsync" command because I don't see what to do?
Running "rsync -aviS" as is only returns an error.

Best regards.
you stated in your OP:

Quote:
I have an application which automatically copies files and directories
from a directory "Ds" to another one "Dt".
use rsync instead of copy. cp typically does not preserve any permissions, etc... this is what you are after. that will continue to fail without setting restrictive permissions that always create RWX for user, group, other every time that user touches any file.

to get around that use rsync instead.

man pages are your friend as is good.

http://linux.die.net/man/1/rsync

https://www.google.com/search?q=what...m=119&ie=UTF-8
 
Old 03-13-2014, 04:19 AM   #8
leamassiot
Member
 
Registered: Dec 2005
Location: France
Distribution: Debian
Posts: 123

Original Poster
Rep: Reputation: 17
In reply to notKlaatu:
Quote:
Then you are looking to set attributes on the filesystem.

So, in Samba you are configuring the shared directory and setting a umask for the directories. On many Linux filesystems, you can do this with `setfacl`. I have never had the occasion to be this granular so you'll need to read the man page or an online tutorial to learn more about it, but that is probably what you are looking for. You want to set a mask on directory 'Dt' such that anything written into it has specific attributes; that's done with ACL's via `setfacl`.

Good luck!
Ok. Thank you.

If someone knows how to write an ACL which:

- for every new file in a directory "D"
sets its owner to "user1",
its owner group to "group1"
and its permissions to 660

- for every new directory in a directory "D"
sets its owner to "user1",
its owner group to "group1"
and its permissions to 770

please post the appropriate commands to run for it to work on my OS.

Maybe this is not the right way to put things.
Maybe I should better state things like this:
How to write an ACL which:
for every new file in a directory "D":
- grants the read and write permissions to a user "user1",
- grants the read and write permissions to a group of users "group1",
- grants no permissions to others.
for every new directory in a directory "D":
- grants the read, write and execute permissions to a user "user1",
- grants the read, write and execute permissions to a group of users "group1",
- grants no permissions to others.

Best regards,
--
OS: Debian GNU/Linux 7.2 (wheezy)
"/home" partition mounted with ACL support.
 
Old 03-13-2014, 04:40 AM   #9
leamassiot
Member
 
Registered: Dec 2005
Location: France
Distribution: Debian
Posts: 123

Original Poster
Rep: Reputation: 17
In answer to lleb:
Quote:
use rsync instead of copy. cp typically does not preserve any permissions, etc... this is what you are after. that will continue to fail without setting restrictive permissions that always create RWX for user, group, other every time that user touches any file.

to get around that use rsync instead.

man pages are your friend as is good.

http://linux.die.net/man/1/rsync

https://www.google.com/search?q=what...m=119&ie=UTF-8
Ok, very good.

A command like this one:

Code:
user1# rsync -o -g -p test.txt <D>/text_2.txt
preserves the owner, the owner group and the permissions of "test.txt" when creating "test_2.txt".
So, if the owner of "test.txt" is "user1", its owner group "group1" and its permissions "660", "test_2.txt" will also have its owner set to "user1", its owner group set to "group1" and its permissions set to "660".

"user1" also needs to have the write permission on the directory <D>.

For people interested:
I use WinSCP.
I run the "Custom Command":
rsync -o -g -p ! <D>/!

Best regards.
 
  


Reply



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
vi changing owner and group on a force write fukawi2 Linux - Security 9 11-05-2020 12:49 PM
What is .gvfs? Owner is ?, group ?, permissions are ?????????, size is ? 809areacode Linux - General 1 08-19-2011 12:02 PM
Owner of a directory different than file owner problems Guardian-Mage Linux - Server 4 04-24-2009 10:26 AM
/etc/mtab has bad permissions/owner/group on Ubuntu Edgy ImpactDNI Linux - Software 1 11-08-2006 06:56 PM

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

All times are GMT -5. The time now is 05:36 PM.

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