📜 ⬆️ ⬇️

Shared directory on Linux desktop

Imagine the situation, Linux is installed on the home computer. This computer is used by you and your wife. For this, the system has two users, each with its own mailer settings, its own bookmarks, its own WM, and finally its own wallpaper. It seems that everything is good and everyone is happy with everything, but there is some content peculiar to the desktop, for which it is necessary to organize general and, above all, full access for both users. What can be done here? Several decisions immediately come to mind:

1. Set the corresponding umask for the shared directory;
2. Set the appropriate default acl;
3. Set the SGID bit.

Well, they applied one of the solutions, or all at once. It seems everything works. Both users have full access to the entire contents of the shared directory, the new files in this directory inherit its rights, but you have dropped photos from the camera into this directory. Your wife enters the system under her own user and decides to change these photographs a little, only when you save, a message about insufficient rights appears. It turns out that the files you copied did not inherit the rights of the shared directory. Why? Yes, because the cp utility doesn't care about your umasks and acl's. It copies files with preserving the original rights, or the rights are reduced, it all depends on the rights to the directory where we copy.
')
In this article I will offer my own way to solve this problem. No, the method is not beautiful and not elegant, therefore, together with the description of the method, I propose that the Habrasoobschestvu discuss this issue and offer their solutions for organizing a common directory on the Linux desktop.

Required Tools


There are only two of these tools:
1) fam or gamin - file system monitoring service. What to use, you choose, but I recommend gamin, because the fam itself is outdated, and gamin is more stable.
2) fileschanged - a small console utility, which is essentially a fam or gamin client program .

Usage example


Let our experimental directory be ~ / Photos. All actions will be carried out with him.
First we need to create a script / usr / local / bin / script with the following content

#!/bin/bash
if [ -d "$2" ]; then
chmod 774 "$2"
elif [ -f "$2" ]; then
chmod 664 "$2"
fi


This script will change the permissions for all new items in the ~ / Photo directory . For rw-rw-r-- files, for rwxrwxr-x directories. If you use fam , do not forget to run fam daemon

/etc/rc.d/fam start

Now with the help of fileschanged, you need to run this script.

fileschanged -cCfr -x /usr/local/bin/script ~/ &

That's all. Now fileschsnged will listen to what fam (gamin) is saying about changes in the ~ / Photos directory and apply the / usr / local / bin / script script to everything new .

How do you organize the general catalog?

Written based on an article from my blog.

UPD: Another solution suggested by khim . The bottom line is:
1. Both users must be in different primary groups. So it seems made at RedHat. At creation of the new user the group with the same name is created.
2. Create a family group for both users (for example).
3. We make the family group the owner of the shared directory and set its rights to it is 2775.
4. For gnome, we run gconf-editor and in the / system / storage / default_options / vfat section we install umask 002. This means that on all mounted devices with FS, the file rights will be 664. I cannot say how to do this in kde it is not at hand.
5. Now feel free to copy the content in the general directory. The owner of this content will be the family group (inherits from the directory), and the rights will remain 664.
Ps. The first point is to ensure that the copied files from the fat carrier in the personal directory are accessible only to you.
Pss. All this is good, but what about CDs? There the files are read only and the umask cannot be installed.

Source: https://habr.com/ru/post/64868/


All Articles