Friday, 11 October 2013

Allowing multiple users to write to directory in Linux

Let's say you have in your filesystem a directory /AlicesAdventures owned by Alice, and you would like to also allow Bob to read/ write to it. You can do the following:

# create a new user group
groupadd AlicesAdventuresUsers

# add Alice to the new group
usermod -a -G AlicesAdventuresUsers Alice

# same for Bob
usermod -a -G AlicesAdventuresUsers Bob

# pass ownership of /AlicesAdventures to AlicesAdventuresUsers
# (recursive)
chgrp -R AlicesAdventuresUsers /AlicesAdventures

# make sure that all newly created files in /AlicesAdventures
# will belong to AlicesAdventuresUsers
chmod g+s /AlicesAdventures

Sure, you could also make /AlicesAdventures writeable by everyone, but do you really trust Chuck? :-)


N.b.: You may need to run the above commands as root.

No comments:

Post a Comment