My username is a member of multiple groups. How do I work with multiple groups?

MSI Groups

Your MSI user account is associated with the PI who created the account; this PI's group is known as your primary group. You can have your user account added to additional “secondary” groups as well. This allows you to have access to another group’s files, quota space, and SUs, which is useful if you are working with another PI on a project. To have your account added to Goldy Gopher’s group have Goldy (the PI) add you via the group page. Instructions for doing so can be found here

Quickstart

Add these commands to your .bashrc file (located in your home directory). The rest of this document explains these commands in detail. Replace “gopherg” with the name of your secondary group:

# define an environment variable to hold the active group
export MYGROUP=$(id -gn)

# group follows along with ssh
function ssg ()
{
\ssh $@ -t "newgrp \- $MYGROUP"
}
alias ssh=ssg

# switch groups by typing the name of the group (repeat this line for additional secondary groups)
# Replace gopherg with the name of your secondary group!
alias gopherg="newgrp \- gopherg"

# Add your active group to your command prompt (and add some color)
GROUP_NAME=$(id -gn)
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u-$GROUP_NAME@\h\[\033[00m\]:\[\033[01;33m\]\w\[\033[00m\]\$ '

Switching Groups

When you log in to MSI your active group is your primary group. To switch to the gopherg group use the newgrp command:

$ newgrp - gopherg

Note

The dash in the newgroup command causes your environment to be reinitialized which bumps you back to your home directory (among other things), but is neccessary for the .bashrc modifications listed on this page to work. If you omit the dash and run “newgrp gopherg” you will stay in your current directory and keep your current environment, but alias definitions are lost.

To make it easier to switch to the group gopherg you can add an alias to your .bashrc:

alias gopherg="newgrp \- gopherg"

Then you can switch to the group just by typing its name:

$ gopherg

To switch back to your primary account type “exit” or press control-d

Files

When you create new files they will be owned by your active group. If your active group is not gopherg and you create files anywhere in gopherg’s group directory the filesystem will immediately change the group ownership of the files to gopherg. In some cases, like unzipping files that were originally zipped within a different group, ownership will not be changed properly. This may result in a “Disk quota exceeded” error, so it is recommended you first change your active group before creating files in another group’s home directory, and verify correct group ownership after file creation.

SLURM Jobs

SLURM jobs submitted with the sbatch command are associated with your current active group fairshare unless changed with the "-A" flag. To charge usage to group gopherg you can use “#SBATCH -A gopherg” in the pbs script, or add “-A gopherg” to the sbatch command line.

SLURM jobs execute as the current active group. To have a job execute as group gopherg, submit the job like this:

sg gopherg -c 'sbatch myjob.sh'

 

SSH

When you use ssh to connect to another MSI computer your active group on the new computer will be your primary group, regardless of what your active group was on the previous computer. To have your active group follow you around add these lines to your .bashrc file:

export MYGROUP=$(id -gn)
function ssg ()
{
\ssh $@ -t "newgrp \- $MYGROUP"
}
alias ssh=ssg

Command-Prompt

The default command-line prompt shows your username. Add these lines to your .bashrc to have the username and active group displayed so it’s easy to see what group you are working in:

# Set the command prompt.
GROUP_NAME=$(id -gn)
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u-$GROUP_NAME@\h\[\033[00m\]:\[\033[01;33m\]\w\[\033[00m\]\$ '
 
Category: 
Environment