h1

Manage multiple Linux users editing the same projects

March 1, 2012

I work on projects on remote servers where a number of developers might login and edit a file. This usually results in the file permissions changing so that they own it which can cause problems. A simple solution is for everyone to be a member of the same group, then make it so that by default it is that group that is set on a file when someone creates it. We also then want to set the group write flag by default as well so that anyone can edit that file.

The steps involved in setting this up on a server are as follows.

— create a new group everyone will share (mygroup)
groupadd mygroup

— create any new users (if required, this can be skipped if you have existing users)
useradd -G mygroup -m myusername
passwd myusername

— Make the default group for a user to be mygroup so everyone in that group can access their files
usermod -g mygroup myusername

— Set the global umask in the global bashrc file so that all users set group write on files (needs everyone to logout and in again)
vim /etc/bashrc
umask 002

Note for the bashrc thing to work it has to be called from the user’s local .bashrc file intheir home directory. Most linux distros do this by default but it is possible for individuals to remove the include for the global bashrc which will then mean that group write is not set on files they create. The bit in the users .bashrc file that includes the global bashrc looks like this…

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

Now if your shared work is in /var/www/html for example, you’ll need to change the group owner on all files in that directory to the new mygroup

chgrp -R mygroup /var/www/html

And you will also want to make sure every file is writable by the group

chmod -R g+w /var/www/html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: