Skip to content

User Accounts

To add, update and delete user accounts on the Monolithe there are 3 dedicated scripts presented in the following sections. These scripts are only available on the frontend (monolithe.soc.lip6.fr) and located in the /nfs/sbin folder. To execute them you need to be in the sudoers group (= having root privileges).

Description

adduser-nfs

To add a new user on the Monolithe you need to call the adduser-nfs script. The latest will create an account on the frontend and on all the available nodes. The users creation on the nodes is performed thanks to Slurm (based on srun command).

For instance, if you want to add a new user named toto-nfs you can do:

sudo adduser-nfs toto-nfs

The previous command will ask you to enter en password.

If you prefer to directly enter a password you can also call adduser-nfs like this:

sudo adduser-nfs toto-nfs totopasswd

adduser-nfs will automatically create a home directory located here: /nfs/users.

Note

By convention on the frontend, logins are postfixed by -nfs. This clearly indicates that these accounts have a home directory on the NFS. Again, by convention, the UIDs are set to a value greater than 1200. It ensures that these UIDs are not already in use on the nodes.

deluser-nfs

To delete a user on the frontend and on the compute nodes, you can call the deluser-nfs script:

sudo deluser-nfs toto-nfs

This will erase the user from the system database but will keep the user home.

If you also need to delete the home directory you can do:

sudo deluser-nfs toto-nfs --delete-home

It will remove the user from the system database and it will delete the /nfs/users/toto-nfs folder.

upuser-nfs

When adding new nodes to the cluster, the user accounts are not automatically created on the new machines. If you want to propagate an user account on a new node that has been setup on the Slurm cluster you can do:

sudo upuser-nfs toto-nfs

This script also checks that the UIDs between the frontend and the compute nodes are the same. If not, the script will stop with a error telling you which UIDs differs from the master and on which Slurm partition.

Info

Most of the time you will want to add all the NFS users to the new node. For this, you can directly call the following command:

sudo upusers-nfs
This will call the previous upuser-nfs (user without "s") command on all the available logins automatically.

Tips

For each user, on each node, a space on the local drive is automatically created here: /scratch/toto-nfs. It is useful when a large amount of files is generated. In this particular case, the performance of the NFS is pretty bad and it is advised to use the scratch space.

Source Codes

adduser-nfs

adduser-nfs
#!/bin/bash
#set -x

if [[ $UID != 0 ]]; then
    echo "Please run this script with sudo:"
    echo "sudo $0 $*"
    exit 1
fi

if [[ $# == 0 ]]; then
    echo "usage: $0 username [userpasswd]"
    exit 1
fi

USERNAME=$1
REGEX=".*-nfs$"
USERNAME_CHECK=$(echo $USERNAME | grep "$REGEX")
if [ -z "$USERNAME_CHECK" ]
then
    echo "The username should match the following regex \"$REGEX\""
    exit 1
fi

PREVUSERUID=$(cat /etc/passwd | cut -d ':' -f 4 | grep "12[0-9][0-9]" | sort | tail -n 1)
let "USERUID=$PREVUSERUID+1"

if [ -z "$PREVUSERUID" ]
then
    USERUID=1201
    echo "This is the first NFS user and its id is: $USERUID"
else
    echo "Using the following userid: $USERUID"
fi

# create the new account on the frontend
if [[ $# == 1 ]]; then
    adduser $USERNAME --home /nfs/users/$USERNAME --shell /bin/bash --uid $USERUID
    rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
else
    USERPASSWD=$2
    adduser $USERNAME --home /nfs/users/$USERNAME --shell /bin/bash --uid $USERUID --disabled-password --gecos ""
    rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
    echo $USERNAME:$USERPASSWD | chpasswd
fi

cd $(dirname $0)

# create the new account on the nodes by calling the update script
./upuser-nfs $USERNAME

deluser-nfs

deluser-nfs
#!/bin/bash
#set -x

if [[ $UID != 0 ]]; then
    echo "Please run this script with sudo:"
    echo "sudo $0 $*"
    exit 1
fi

if [[ $# == 0 ]]; then
    echo "usage: $0 username [--delete-home]"
    exit 1
fi

if [[ $# -gt 1 ]]; then
    if [ "$2" != "--delete-home" ]; then
        echo "usage: $0 username [--delete-home]"
        exit 1
    fi
fi

USERNAME=$1
REGEX=".*-nfs$"
USERNAME_CHECK=$(echo $USERNAME | grep "$REGEX")
if [ -z "$USERNAME_CHECK" ]
then
    echo "The username should match the following regex \"$REGEX\""
    exit 1
fi

USERUID=$(cat /etc/passwd | grep "^$USERNAME:.*" | cut -d ':' -f 4)
echo "The username has be found, it has the following uid: $USERUID"

echo "Deleting the account on the master node..."
deluser $USERNAME
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi

if [[ $# -gt 1 ]]; then # --delete-home is set
    echo "Removing \"/nfs/users/$USERNAME\" ..."
    rm -rf /nfs/users/$USERNAME
    rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
fi

# delete the account on the other nodes
PARTITIONS=$(sinfo | grep "idle" | cut -f 1 -d " ")

cd /nfs
echo "List of the Slurm partition:"
for PARTITION in $PARTITIONS; do
    # remove the extra * character at the end of the default partition
    PARTITIONCHECK=$(echo $PARTITION | grep ".*\*$")
    if [ -z "$PARTITIONCHECK" ]
    then
        PARTITION=$PARTITION
    else
        PARTITION=$(echo ${PARTITION:0:-1})
    fi

    # check if the user exists on the node
    USERNAMEEXIST=$(srun -p $PARTITION cat /etc/passwd | cut -d ':' -f 1 | grep "^$USERNAME$")

    if [ "$USERNAME" = "$USERNAMEEXIST" ]; then
        # check if the user id is the same on the master and on the partition
        USERIDCHECK=$(srun -p $PARTITION cat /etc/passwd | grep "^$USERNAME:.*" | cut -d ':' -f 4)
        rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi

        if [ "$USERUID" = "$USERIDCHECK" ]; then
            echo "Deletion of the user on the following Slurm partition: $PARTITION ..."
            srun -p $PARTITION deluser $USERNAME
            rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
        else
            echo "(ERROR) User id mismatch on the master (uid = \"$USERUID\") and the partition \"$PARTITION\" (uid = \"$USERIDCHECK\")!"
            echo "It should never happend! Exiting..."
            exit 1
        fi
    else
        echo "Skip the deletion of the user on the following Slurm partition: $PARTITION ..."
    fi
done

upuser-nfs

upuser-nfs
#!/bin/bash
#set -x

if [[ $UID != 0 ]]; then
    echo "Please run this script with sudo:"
    echo "sudo $0 $*"
    exit 1
fi

if [[ $# == 0 ]]; then
    echo "usage: $0 username"
    exit 1
fi

USERNAME=$1
REGEX=".*-nfs$"
USERNAME_CHECK=$(echo $USERNAME | grep "$REGEX")
if [ -z "$USERNAME_CHECK" ]
then
    echo "The username should match the following regex \"$REGEX\""
    exit 1
fi

USERNAMEEXIST=$(cat /etc/passwd | cut -d ':' -f 1 | grep "^$USERNAME$")

if [ -z "$USERNAMEEXIST" ]
then
    echo "The username cannot be found"
    exit 1
fi

USERUID=$(cat /etc/passwd | grep "^$USERNAME:.*" | cut -d ':' -f 4)

echo "The username has be found, it has the following uid: $USERUID"

# create the account on the nodes
PARTITIONS=$(sinfo | grep "idle" | cut -f 1 -d " ")

cd /nfs
echo "List of the Slurm partition:"
for PARTITION in $PARTITIONS; do
    # remove the extra * character at the end of the default partition
    PARTITIONCHECK=$(echo $PARTITION | grep ".*\*$")
    if [ -z "$PARTITIONCHECK" ]
    then
        PARTITION=$PARTITION
    else
        PARTITION=$(echo ${PARTITION:0:-1})
    fi

    # check if the user exists on the current node
    USERNAMEEXIST=$(srun -p $PARTITION cat /etc/passwd | cut -d ':' -f 1 | grep "^$USERNAME$")

    if [ "$USERNAME" = "$USERNAMEEXIST" ]; then
        # check if the user id is the same on the master and on the partition
        USERIDCHECK=$(srun -p $PARTITION cat /etc/passwd | grep "^$USERNAME:.*" | cut -d ':' -f 4)
        rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi

        if [ "$USERUID" = "$USERIDCHECK" ]; then
            echo "Skip the creation of the user on the following Slurm partition: $PARTITION ..."
        else
            echo "ERROR: the user id mismatch on the master (\"$USERUID\") and the partition \"$PARTITION\" (\"$USERIDCHECK\")!"
            echo "It should never happend! Exiting..."
            exit 1
        fi
    else
        echo "Creation of the user on the following Slurm partition: $PARTITION ..."
        # adduser work differently on Fedora... It is a shame but what can we do?
        if [ "$PARTITION" = "m1u" ]; then
            srun -p $PARTITION adduser $USERNAME --home /nfs/users/$USERNAME --shell /bin/bash --uid $USERUID --no-create-home
            rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
        else
            srun -p $PARTITION adduser $USERNAME --home /nfs/users/$USERNAME --shell /bin/bash --uid $USERUID --no-create-home --disabled-password --gecos ""
            rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
        fi
    fi

    # if the partition is "brub", add the user to the "sog" and "dialout" groups to be able to use the energy measurements
    if [ "$PARTITION" = "brub" ]; then
        srun -p $PARTITION usermod -a -G sog,dialout $USERNAME
        rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
    fi

    # if the partition is "em780" or "x7ti", add the user to the "render" group to be able to use OpenCL
    if [ "$PARTITION" = "em780" ] || [ "$PARTITION" = "x7ti" ]; then
        srun -p $PARTITION usermod -a -G render $USERNAME
        rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
    fi

    # add users to the `video` on Orin boards (to use PoCL)
    if [ "$PARTITION" = "oagx" ] || [ "$PARTITION" = "onx" ] || [ "$PARTITION" = "onano" ]; then
        srun -p $PARTITION usermod -a -G video $USERNAME
        rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
    fi

    $(srun -p $PARTITION [ -d "/scratch" ])
    rc=$?;
    if [[ $rc == 1 ]]; then
        echo "Creation of the scratch folder: $PARTITION ..."
        $(srun -p $PARTITION mkdir /scratch)
        rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
    fi

    $(srun -p $PARTITION [ -d "/scratch/$USERNAME" ])
    rc=$?;
    if [[ $rc == 1 ]]; then
        echo "Creation of the scratch folder for '$USERNAME' user: $PARTITION ..."
        $(srun -p $PARTITION mkdir /scratch/$USERNAME)
        rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi

        $(srun -p $PARTITION chown -R $USERNAME:$USERNAME /scratch/$USERNAME)
        rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
        $(srun -p $PARTITION chmod -R 700 /scratch/$USERNAME)
    fi
done

upusers-nfs

upusers-nfs
#!/bin/bash
#set -x

if [[ $UID != 0 ]]; then
    echo "Please run this script with sudo:"
    echo "sudo $0 $*"
    exit 1
fi

USERNAMES=$(cat /etc/passwd | grep "\:12[0-9][0-9]\:" | cut -d ':' -f 1)

cd $(dirname $0)

for USERNAME in $USERNAMES; do
    echo "Updating user: $USERNAME"

    # create the current account on the nodes by calling the update script
    ./upuser-nfs $USERNAME
done