Adding Additional User Accounts to a VM

This document provides instructions and commands to add additional user accounts to existing cloud VMs, steps are provided for each supported operating system.

Prerequisites

  1. sudo level access to the machines you wish to add the new users to.

  2. The username of each user you wish to add.

    1. For STFC users we recommend using their Fed ID (STFC Username) for consistency.

  3. The corresponding SSH Public Key for each user.

We do not recommend setting passwords for added users and as such the following instructions only provide steps to allow additional users to authenticate using SSH Key based authentication.

Rocky Linux

 

 

Ubuntu

For each user, do the following:

First you create the user account using the adduser command. Note that this command will prompt you for some additional details.

sudo adduser <username> --disabled-password

You then want to set up the user’s SSH authorized keys file and add their SSH public key to it using an editor of your choice. Please note that key formatting is very important, several examples of acceptable key types and formats are provided below.

sudo mkdir /home/<username>/.ssh sudo touch /home/<username>/.ssh/authorized_keys sudo vim /home/<username>/.ssh/authorized_keys sudo chown -R <username>:<username> /home/<fed-id>/.ssh sudo chmod -R 0700 /home/<username>/.ssh

Your user should now be able to log in to your machine with their SSH public key using the following command.

ssh <username>@<ip address>

If you also want the newly added user to have sudo permissions then you need to edit the /etc/sudoers.d/cloud file using the following command.

Adding the following line to the bottom. Note that because we do not set a password for the user, the NOPASSWD option is necessary.

Example Public Keys

The following keys are all examples used to demonstrate acceptable formatting of public keys in authorized keys files.