Unix make all files copied into directory owned by me

0

1

I am working with a group on a supercomputer and we are storing all project files in my home directory, the problem is if I need to manage some of the files, I can't because they own the files. I need a way for all of the files placed inside the directory in my home folder to be owned by me. The other people are uploading the files using SFTP

DontTurnAround

Posted 2012-06-27T17:22:47.307

Reputation: 187

Would group ownership be good enough? – Jon Lin – 2012-06-27T17:24:58.183

We're all in the same group. The problem is I want everyone to be able to write to this directory and all files inside it, so when someone puts a file in the directory is is -rwxrwx--- so everyone can overwrite the files with the newest version when they have a newer versiom – DontTurnAround – 2012-06-27T18:19:52.193

Which Unix specifically? – dave4420 – 2012-06-27T22:30:33.630

Answers

3

You can change the owner with chown but it is not a good solution, because you must do this always.

I would solve your task using SGID bit for a directory.

You can set this bit to the directory where users upload files and then these files will have your group as a group owner.

$ mkdir -p ~/incoming/
$ chmod o+wt ~/incoming/   # making the directory world writeable; setting sticky bit to avoid deletion of files
$ chmod g+s ~/incoming/    # setting setgid for the directory

And don't forget to set umask 002 for the ftp/sftp server.

For SFTP-server you can do this in sshd_config. Rewrite the line with sftp-server in this way:

Subsystem sftp /usr/lib/openssh/sftp-server -u 022

Igor Chubin

Posted 2012-06-27T17:22:47.307

Reputation: 166

This didn't work – DontTurnAround – 2012-06-27T18:18:20.853

What do you mean "didn't work"? Whicg group is the group owner of files in the incoming directory? – Igor Chubin – 2012-06-27T19:14:37.713

2

As root, run chown username:group -R * and replace your name and group.

Now of course they might not be able to edit them now, so add them to your group and give it group-editable permissions. (chmod xyz -R *) and replace "xyz" with the appropriate permissions.

ionFish

Posted 2012-06-27T17:22:47.307

Reputation: 163

1

If it's just a matter of you needing to be able to edit the files in a certain directory, where other people have ownership of the files, you can create a group and add some modes to this directory. (Replacing folder with the path of your home directory):

  1. Create a group (if you don't already have an existing one) that you and all the other people you are working with belong to. See the groupadd command. And then add everyone to that group using usermod. You can verify who's in this group by looking at /etc/group file.

  2. Change the folder's default mask so that group are read/write.

    setfacl -d -m g::rwx folder
    
  3. Create a setgid so that when new files are placed in this directory, they belong to the group:

    chmod g+ws folder
    
  4. Now set the group and the ownerships:

    chown -R youruser:thegroupname folder
    chmod -R g+w folder
    

If you really want to force all files to be owned by you, you need to make it so the mechanism that they place these files change the ownership to you, if it is either ftp or samba etc. Otherwise you can use a file watcher like lsyncd to watch the folder and change the ownership when new files appear.

Jon Lin

Posted 2012-06-27T17:22:47.307

Reputation: 755

This didn't work – DontTurnAround – 2012-06-27T18:18:09.607

@user1036238 is the filesystem that folder is on mounted with the acl option? (You should be able to see the mount options in /etc/fstab) – Jon Lin – 2012-07-13T21:30:35.457