Results 1 to 6 of 6
I am running a shell script as the user "redhatuser01" and this script creates a files in the home directory of another user "redhatuser02" (/home/redhatuser02/sample.txt) but the ownership of this ...
- 08-04-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 8
Changing Ownership of a File
I am running a shell script as the user "redhatuser01" and this script creates a files in the home directory of another user "redhatuser02" (/home/redhatuser02/sample.txt) but the ownership of this file is currently "redhatuser01". How can i change the "ownership of this file to the user "redhatuser02"? (My constraint is that I cannot sudo as redhatuser2 and create the file).
- 08-04-2010 #2
By using the chown, chgrp commands?
Issue these commands for more help, in a terminal window.
Code:man chown
Code:man chgrp
I do not respond to private messages asking for Linux help, Please keep it on the forums only.
All new users please read this.** Forum FAQS. ** Adopt an unanswered post.
- 08-04-2010 #3
The chown utility allows you to change the owner of a file. Run the command "man chown" for details.
Note that as a general rule, you shouldn't be creating files in another user's home directory. It is fairly common for a user's home directory to be unwritable for other users in any case. You should treat a user's home directory as their own private domain.DISTRO=Arch
Registered Linux User #388732
- 08-04-2010 #4
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 08-04-2010 #5Just Joined!
- Join Date
- Jul 2010
- Posts
- 8
Thanks for your suggestion.
I had tried using chown to change the permission but got "Operation not permitted " error. Infact "redhatuser02" user's secondary group is "redhatuser01" and the file created there has got execute permission set to it. Am i missing here anything? or is it really possible ?
(I understand that its not a good practice to create a file under some other user's home directory and th
is is not part of a production code and i am trying to test a concept.)
- 08-04-2010 #6
Please read these:
and google this: "unix filesystem standard" (unix filesystem standard - Google Search)Code:man chown man chgrp man chmod man usermod man umask
you should under no circumstances allow one user to write to another users home directory. a common place where to put variable data that can be shared is /var.
i.e. create a group "sharegroup", add both users to that "sharegroup" using usermod, create a directory under var with read/write permissions for the group "sharegroup" (g+rw) and let both users access those files. you could even make up a symbolic link to those files in their home directory or make a hardlink if the files are shared through ftp which do not follow symbolic links. note: you would also have to change the "umask" of both users in order to create files with the g+rw permissions by default. otherwise you would need a cronjob to do that job for you OR make sure the files that are being written are "chmod"-ed to g+rw after creation (if you have a script that is being run, it is just one more line).
if you need more fancy things google this:
ACL (access control list)
this little thing allows you to set access permissions on a file/directory for multiple users/groups. it was invented cause certain situations like this here are quite complicated to handle only with the categories user, group and other.
this said, you would be able to do everything without the need of a "sharegroup", but with the drawback that things are no longer obvious and easy understandable for others that ask themselves "why is this user writing to that folder and how does it work?".Last edited by Kloschüssel; 08-04-2010 at 06:26 AM.


Reply With Quote
It should give you 