2

I have a 15.04 machine with basically 2 user accounts, an admin and a restricted user. What I want is that both of them have separate home directories (for system/application settings etc.), but use the same data directories:

  • Desktop
  • Documents
  • Music
  • Pictures
  • Public
  • Templates
  • Videos
  • and maybe some more, program-specific data folders...

Those directories therefore have to be outside of those two users' home directory, e.g. be located in /home/shared-data/ or something like that and both users need full access on them.

If I navigate through that directory and back upwards in the hierarchy, I want to come out in the same user's home directory where I started, if possible. And the real shared directory should not be publicly accessible by new users, just by those users I specifically allowed.

Also, new files and folders created there should automatically be accessible to both users.

So what is the easiest way to move all data from the users' current home directories to this external location, then replacing the original folders with links/mounts/whatever to the new shared directory, so that it looks like before?

1

Don't move anything. Just use links. For example, say your normal user is usera and your second one is userb. Presumably, userb is a brand new account and doesn't have any data you want to keep. So, delete the directories in question and recreate them as links, then set up the right permissions:

  1. Delete the directories and recreate as links

    sudo rmdir ~userb/{Desktop,Documents,Music,Pictures,Public,Templates,Videos}
    for i in Desktop Documents Music Pictures Public Templates Videos; do
        sudo -u userb ln -s ~usera/"$i" ~userb
    done
    
  2. Create a new group and add both users to this group:

    sudo groupadd foo
    sudo usermod -aG foo usera
    sudo usermod -aG foo userb
    
  3. Change the group ownership of the directories you want to share to this new group:

    chgrp -R foo ~usera/{Desktop,Documents,Music,Pictures,Public,Templates,Videos}
    
  4. Set the permissions on the target directories to rwx for the group and set the SETGID bit on the directory so that new files will belong to the right group.

    chmod -R g+rwxs ~usera/{Desktop,Documents,Music,Pictures,Public,Templates,Videos}
    
  5. Set the Access Control List settings to set the permissions for newly created files/directories:

    setfacl -d -m g:foo:rwx ~usera/{Desktop,Documents,Music,Pictures,Public,Templates,Videos}
    

That's it. Now, the directories in ~/userb are links to those in ~/usera and both users have read/write access to them.

| improve this answer | |
  • I want the common directories to be located outside the user's home directories, please... Because I will clone the user profile and don't want to have the stuff in there and for some other reasons. – Byte Commander Jun 30 '15 at 10:52
  • @ByteCommander OK, then link to both. I mean, create the directories and make links pointing to them in both $HOMEs. Everything else is the same. – terdon Jun 30 '15 at 10:54
  • Who should be the owner user of the shared directories? – Byte Commander Jun 30 '15 at 11:05
  • @ByteCommander one of the two users or even someone else. It's the group permissions that are important here. – terdon Jun 30 '15 at 11:31
  • I have a problem. If a user creates new files in there, those are owned by him and his native group, not by the shared group! And this makes these files unusable for the other user. This is severe for my shared Firefox profile, as once I opened it with userb, he modified file permissions and when I open it with usera again, he can't access the modified files any more and just deletes/recreates them and my profile is f$$$ed up. Is there a way to automatically change owner(root) and group(foo) of all new and modified files and give the group the same permissions as the owner? – Byte Commander Oct 30 '15 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.