Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have two Linux installations on my computer, with /home on a different partition but shared for the two installs. And each install has a different username to avoid conflicts. The thing is, I'm a developer, I don't want mix users, but I want to setup permissions for a shared folder.

Example,

  • Ubuntu, main user: raul, home folder: /home/raul
  • Fedora, main user: ricardo, home folder: /home/ricardo
  • I want a /home/shared where raul & ricardo have permissions over this folder, maybe www-data and root, but any other user on any Linux distro.

I hope you got my problem.

EDIT: This seems to be more complex than expect.

This note is the best I can explain, with my actual English level, so please be nice.

On the same computer, I have distros A and B installed. Distros A and B are sharing /home in another partition but have different users... so I have /home/a for user A in distro A, /home/b and you know... So I like to have a folder for example /home/shared where users A and B can both read and write to the folder, like part of the same group, BUT user A doesn't exist on distro B and vice versa. Then how do I tell each distro to make me a group with a user from another distro?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

Not sure exactly what your question is. Can you be more specific? Specifically, I'm having difficulty parsing

I want a /home/shared where raul & ricardo have permission over this folder, maybe www-data and root, but any other user on any linux distro.

Do you want to know how to set up a shared folder/partition? If so, you could just set up a group in each installation with the same group id. Then perhaps use acl to make sure group has rw permission to the partition.

man addgroup says

A GID will be chosen from the range specified for system GIDS in the configuration file (FIRST_GID, LAST_GID). To override that mechanism you can give the GID using the --gid option.

So you could do

addgroup [options] [--gid ID] group

where group and ID is the same in both installations.

For a tutorial about acl see Using ACLs with Fedora Core 2, and see my answer to a recent question about sharing a directory between two users. Obviously, you'll need to mount the partition with acl support on both installations.

Once acl is set up, all files and directories in the folder will have group permissions rw and so raul from one installation and ricardo from the other installation will both be able to read and write to that folder.

EDIT: In response to raul's comment below:

If I understand your question correctly, and you are trying to share data between two www-data users on two installations, then this a slightly different question than the one you seemed to be asked with raul and ricardo, because in this case, the users would be the same.

www-data would be typically created by a web server installation like apache, so creating them with matching ids would be difficult unless it was already the case (see below). I think there should be no problem in altering the uids/gids after the event to match, but I'm not 100% sure about that. Perhaps the experts here can advise.

Note that Debian defaults to uid/gid=33 for www. It is possible it would not be the same for other Linux distributions. However, if your installations were both the same distribution, the ids would very likely match. Indeed, if this were the case, you could just use the www-data group as your group, and you would not have to do anything.

share|improve this answer
    
Well, the problem is that I do not know if what I'm asking it is possible. Yes, I want to share a folder between two users from different linux installation. My example try to figure out if besides simple sharing, can I also setup some kind of permission. –  raulricardo21 May 9 '11 at 15:52
    
@raulricardo21: It's possible. i outlined how to do it. though I did not test it. Still unclear on your reference to www-data and root. Were you just giving examples of possible two users? –  Faheem Mitha May 9 '11 at 16:01
1  
@raulricardo21: I just added that both users will need to exist on both systems with the same uids. I think this will suffice for what you want to do. It may not be necessary though. –  Faheem Mitha May 9 '11 at 16:10
    
ah, the example was because of this, www-data is on both distros, but how can make I setup a group with www-data on a distro don't crash with the www-data on the another one... by the way thank for your answer :) I going to try it –  raulricardo21 May 9 '11 at 16:12
    
@raulricardo21 - The uid's need not match, however, if they will not then it would be prudent to be very mindful of user-level access permissions and to whom they do and do not apply. From a file system perspective the system does not care. –  Tok May 9 '11 at 16:15

Faheem is correct; a shared group option would solve your problem, presuming that I correctly understand your problem.

You can use this command to find the highest, currently assigned GID on each system (the uniq is not necessary but included out of habit):

awk -F':' '{ print $3 }' /etc/group | sort -n | uniq | tail -1

Please note that, whatever the output of this command, there may also be overlaps in unused GID's at a lower value, however, selecting a GID above the printed value will guarantee that neither system already uses the identifier.

Any group permissions set on the folder(s) in question will then apply to all members of the group on both systems.

Please also note that the group names do not need to match, although for your own sanity this may be desirable.

To add one or more users to a group, depending on your Linux distribution, you may have access to the gpasswd command:

gpasswd -a <user> <group/GID>

Lacking this utility, or by preference, you can make the same change by executing:

usermod -G $(groups <user> | sed 's/ /,/g'),<new group> <user>

Please note that this command presumes that you desire to set the supplementary group rather than the primary group for the specified user.

share|improve this answer

In the kernel and on the filesystem, users and groups are identified purely through a number, the user ID or group ID. Names for users and groups are only for display convenience and higher-level applications.

When you share a filesystem between several installations, I strongly advise to make sure that any user (or group) who exists on both systems has the same ID on both. That way, ownership of shared files will be the same in all installations. Many user administration GUIs don't let you choose IDs, so you may need to have to use the adduser command (or addgroup) instead.

A user ID doesn't need to be registered in /etc/passwd to “exist”. It's just that files owned by this user would be shown with the user ID instead of a name in ls output and other places. (Similarly you can use chown 1234 /path/to/file to change a file's owner to any ID).

With that in mind, the problem of sharing file ownership between different installations reduces to sharing files on a single installation. See Permission of saved files for a discussion of that topic (advice: use ACLs).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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