LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Creating a group home directory (http://www.linuxquestions.org/questions/linux-newbie-8/creating-a-group-home-directory-648779/)

powerpleb 06-12-2008 06:11 AM

Creating a group home directory
 
I want to create a directory in /home that several users can access so I can put shared files in there (Music, Photos, Videos, etc)
I was thinking I could create a group called 'share' and a directory called /home/share and set it up so members of the group have full access to this directory.
So my questions are...
Do all directories in /home have to be user accounts, ie if I create /home/share will Linux want to create a user called 'share'?
Can groups have /home folders?
Is /home a good place to be storing shared files?

I ask this because I have /home on a large partition and it would be nice to have users' files and shared files kept on the same partition.

ranger_nemo 06-12-2008 06:29 AM

Your plan is pretty much spot-on... /home is the best place for user data files.

No, your system won't require you to create a user to make a new directory in /home. You can create all the subdirectories you want.

The one stumbling point might be adding new files and subdirectories to /home/share... When you first create it and stuff a bunch of files in there, you will have use chown to change the ownership of the directory and files to the group. If user bob adds more files later, they should be readable by other users, but they might not be writable. You might want to look into Samba or NFS to share the folder to the users, because those programs can take care of file permissions automatic'ly.

powerpleb 06-12-2008 06:42 AM

Quote:

Originally Posted by ranger_nemo (Post 3182453)
You might want to look into Samba or NFS to share the folder to the users, because those programs can take care of file permissions automatic'ly.

So that means I can use NFS to both share it with users on the same machine and users connecting to that machine over LAN. Bloody brilliant.

zQUEz 06-12-2008 07:44 AM

As mentioned, you are basically doing this correctly.
To handle the permissions, you can change the permissions like this:
1) create a folder: mkdir /home/shared
2) make a shared group name in /etc/group
3) make all the users that need access to this shared location, members of the shared group.
4) change the ownership on the shared folder: chown root:shared /home/shared
5) change the perms on the shared folder again: chmod 770 /home/shared
6) apply the guid on the shared folder: chmod g+s /home/shared

Now when new files are added to this folder, no matter who adds them, they will have a group owner the same as the folder owner - e.g. shared. As the group owner has r/w capabilities, they will be able to modify.

ranger_nemo 06-12-2008 09:27 AM

Cool... A sticky group. You learn something new every day.

powerpleb 06-12-2008 05:23 PM

Thanks, that's brilliant.

As directed by someone on another forum I ended up hiding the folder by naming it /home/.share
Then I put symlinks into users' accounts like this:
Code:

ln -s /home/.share /home/user1/share

Michael Scheper 09-06-2012 07:24 PM

Perhaps a more elegant solution?
 
Ubuntu comes with an /etc/profile that includes this:

Code:

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

It should work with any distro, though, and I've successfully created a file called /etc/profile.d/group.sh and given it group read permissions. The script then gets run for members of that group only.

To set the permissions for the script, type:

Code:

sudo chmod 750 /etc/profile.d/group.sh
sudo chown root:group /etc/profile.d/group.sh

If your /etc/profile doesn't already contain the first block of code, you should be able to just copy it in. But I'd replace the -r with -x, thus making it depend on group execute permissions, which is technically more correct. The code to type above would remain the same.

chrism01 09-07-2012 12:42 AM

Just to be pedantic
Quote:

they will have a group owner the same as the folder owner
should read
Quote:

they will have a group owner the same as the folder group owner


All times are GMT -5. The time now is 11:15 PM.