Skip to content

Change primary group

Generally, HPCC users need to request root privilege through the ticket system to change their primary group permanently. However, a user can also use newgrp command to change their primary group temporarily to any one of their groups.

Primary Group Change on Command Line

To change a user's primary group with a command line, simply run

1
[username@dev-intel18 CurrentPath]$ newgrp <Group Name>

Note that <Group Name> has to be one of the user's group names. To find out all group names, please run groups command:

1
2
[username@dev-intel18 CurrentPath]$ groups
chemistry VMD g09 BiCEP education-data ParaView

Here, the primary group is "chemistry", the first group name in the results. After the execution of newgrp command, a new shell session is created and the current environment, including the current working directory remains the same.

1
2
3
[username@dev-intel18 CurrentPath]$ newgrp g09
[username@dev-intel18 CurrentPath]$ groups
g09 chemistry VMD BiCEP education-data ParaView

Note that the primary group is changed to g09. To leave the session, just run "exit" command. It will go back to the previous session with the original primary group (chemistry).

If a user would like to start the shell session with a new primary group as though the user just logged in, the optional "-" flag can be used

1
2
3
[username@dev-intel18 CurrentPath]$ newgrp - g09
[username@dev-intel18 ~]$ groups
g09 chemistry VMD BiCEP education-data ParaView

Using the "-" flag reinitializes the user's environment and the shell session starts from the home directory.

Some users might have the issue of losing the header in front of the prompt after executing the command:

1
2
3
[username@dev-intel18 CurrentPath]$ newgrp g09
bash-4.2$ groups
g09 chemistry VMD BiCEP education-data ParaView

Using source on the default bashrc file will get it back.

1
2
bash-4.2$ source /etc/bashrc
[changc81@dev-intel18 MyCurrentPath]$ 

Note that, if a job is submitted in the session of a new primary group, the environment variables of the new primary group will be used by the job by default instead of the original environment. For more information, please see --export in the table of List of Job Specifications page.

Primary Group Change in Job Script

Many HPCC users have more than one research spaces. In a job running, the user might need their primary group set to be the group of the research space where the output files are. In order to do this, the job script can use newgrp from the beginning of the command lines. For example, an original job script may look like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/bin/bash --login

#SBATCH --time=00:10:00             # limit of wall clock time - how long the job will run (same as -t)
#SBATCH --ntasks=5                  # number of tasks - how many tasks (nodes) that you require (same as -n)
#SBATCH --mem-per-cpu=2G            # memory required per allocated CPU (or core) - amount of memory (in bytes)

module purge
module load GCC/6.4.0-2.28 OpenMPI  ### load necessary modules, e.g. 

srun -n 5 <executable>              ### call your executable (similar to mpirun)

scontrol show job $SLURM_JOB_ID     ### write job information to output file

If the job script is submitted in a research space, adding a few lines can make the primary group the same as the group of the research space:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#!/bin/bash --login

#SBATCH --time=00:10:00             # limit of wall clock time - how long the job will run (same as -t)
#SBATCH --ntasks=5                  # number of tasks - how many tasks (nodes) that you require (same as -n)
#SBATCH --mem-per-cpu=2G            # memory required per allocated CPU (or core) - amount of memory (in bytes)

GroupName=$(readlink -f $PWD|awk -F "/" '{ if ($2=="mnt" && $3=="research" && $4!="") system("ls -ld /mnt/research/"$4"|cut -d \" \" -f 4") }')
newgrp ${GroupName} << EOS

module purge
module load GCC/6.4.0-2.28 OpenMPI  ### load necessary modules, e.g. 

srun -n 5 <executable>              ### call your executable (similar to mpirun)

scontrol show job $SLURM_JOB_ID     ### write job information to output file
EOS

The group name of the research space for job running is automatically determined in line 7. You can also directly set the variable "GroupName" to be the group name of your research space in line 7 if you are sure about jobs running in the research space:

1
GroupName=<group name of your research space>

After the group name of the research space is given, the command lines between line 9 and 16 (inside the two "EOS") will be run under the environment of the new primary group (${GroupName}).

Automatic Primary Group Change after Login

To automatically change your primary group after every login, please submit a ticket to ICER's system administrators with the subject "Membership Changes".

Previously, this page recommended using the PrimaryGroup powertool in your .bashrc. However, this can cause issues when you SSH to other nodes from a development node, and so we no longer recommend using it.