User groups

updated 28 Nov 2023

When you are working in a group on the server, the best way to share code and data and files will usually be some sort of distributed version control system (like Git), but perhaps you don't know how or perhaps it doesn't fit your use case for some other reason. There is an older system available, called user groups (sometimes Unix groups), that can also do the trick. This page documents the basics of working with user groups.

First, you have to get your professor to set one up; and probably also to allocate a shared directory to the group. Once that's done, you're ready to start moving files to that directory and creating and editing files there.

Typical interaction

Before you enter the directory, you'll want to use newgrp (in every PuTTY/terminal window that you're using it) to indicate that further work you do should be available to the other group members. In this example and others, we'll assume that the group in question is called rubberduck—substitute your own group name as appropriate. The directory name might also be somewhere other than /home/shared, so check with your professor on that part too.

newgrp rubberduck; cd
/home/shared/rubberduck; vim sample.txt

Once you've edited a file in the directory, you can see not just the filenames but some additional information about the files by running "ls -l" (those are both lowercase L, not the number one):

ls -l

In the first column, we see that the access control for the newly created file is "-rw-r--r--", meaning that it is Readable and Writeable by the user, but only Readable by anyone else. The fourth column shows us that the file is associated with the group, but to indicate that the file should also be Writeable by the Group, we use the chmod command:

chmod g+w sample.txt; ls -l

From that point on, anyone in your group should be able to edit that file. (Depending on something called your umask, the file might be created without even Read access for the rest of the group, in which case you can use "g+rw" to confer both to the group. You can also adjust your umask to make the chmod step unnecessary.)

Other useful commands

Want to check what groups you've been added to? Type groups by itself to list them.

Possibly you have some already-created files that you move into the directory, or you forgot to use newgrp before creating a file there, and the file is not yet associated to the group:

ls -l

In that case you can use chgrp to change the group association of those files, and probably also chmod as described above:

newgrp rubberduck; chgrp rubberduck
other.txt; chmod g+rw other.txt; ls -l