Adding Users to an Instance
You can add additional users to a compute instance.
If you created your instance using a Linux or CentOS platform image, you can use SSH to access your instance from a remote host as the opc
user. If you created your instance using an Ubuntu platform image, you can use SSH to access your instance from a remote host as the ubuntu
user. After signing in, you can add users to the instance.
If you created your instance using a Windows platform image, you can create new users after you sign in to the instance through a Remote Desktop client.
Creating Additional Users on a Linux Instance
If you do not want to share your SSH key, you can create additional SSH-enabled users for a Linux instance. At a high level, you do the following things:
- Generate SSH key pairs for the users offline.
- Add the new users.
- Append a public key to the
~/.ssh/authorized_keys
file for each new user.
The new users then can SSH to the instance using the appropriate private keys.
If you re-create an instance from a platform image, users and SSH public keys that you added or edited manually (that is, users that weren't defined in the machine image) must be added again.
If you need to edit the ~/.ssh/authorized_keys
file of a user on your instance, start a second SSH session before you make any changes to the file and ensure that it remains connected while you edit the file. If the ~/.ssh/authorized_keys
file becomes corrupted or you inadvertently make changes that lock you out of the instance, you can use the backup SSH session to fix or revert the changes. Before closing the backup SSH session, test all changes you made by logging in with the new or updated SSH key.
To create an additional SSH-enabled user:
- Generate an SSH key pair for the new user.
- Copy the public key value to a text file for use later in this procedure.
- Sign in to the instance.
-
Become the root user:
sudo su
-
Create the new user:
useradd <new_user>
-
Create a
.ssh
directory in the new user's home directory:mkdir /home/<new_user>/.ssh
-
Copy the SSH public key from the text file into the
/home/new_user/.ssh/authorized_keys
file:Note
<public_key> should be the SSH public key itself, not the name of the file containing the key.echo <public_key> >> /home/<new_user>/.ssh/authorized_keys
-
Change the owner and group of the
/home/username/.ssh
directory to the new user:chown -R <new_user>:<group> /home/<new_user>/.ssh
-
To enable
sudo
privileges for the new user, run thevisudo
command and edit the/etc/sudoers
file as follows:-
In
/etc/sudoers
, look for:%<username> ALL=(ALL) NOPASSWD: ALL
-
Add the following line immediately after the preceding line:
%<group> ALL=(ALL) NOPASSWD: ALL
The new user can now sign in to the instance.
-
Creating Additional Users on a Windows Instance
For the most current steps, see Manage User Accounts in the Microsoft documentation.
-
Sign in to the instance using a Remote Desktop client.
-
On the Start menu, click Control Panel.
-
Click User Accounts, and then click User Accounts again.
-
Click Manage another account.
-
Click Add a user account.
-
Enter a User name and Password.
-
Confirm the password, and then create a Password hint.
-
Click Next.
-
Verify the account, and then click Finish.
The new user can now sign in to the instance.