Blankman
Blankman

Reputation: 267020

How to create a user like my default user?

I just started using gcloud, and I noticed when I create a VM or going into cloud console, my full name shows up in the console.

Is there a way to create another user with a more generic name? I don't like having my full name in all my VM's and consoles.

Do I just create another user as 'owner' or is there a best practices around this?

Upvotes: 0

Views: 1326

Answers (1)

John Hanley
John Hanley

Reputation: 81356

When you use gcloud compute ssh [INSTANCE_NAME], gcloud uses your current credentials to create an SSH keypair. The project ssh metadata is then updated with this username and SSH keypair. This is what you are seeing once you connect.

You can create a new SSH keypair with any username that you want. Then you can add this keypair to the instance metadata. Then you can login using that username. This also creates a new home directory in the instance.

For these examples, let's say that you want to create a new user 'development'.

STEP 1: Create a new SSH keypair

ssh-keygen -t rsa -f keypair -C development

This will create two files:

  • keypair - this is your RSA private key. You need this file to login via SSH to your instance using the new username.
  • keypair.pub - this is your SSH-RSA public key. The contents is imported to your instance. Display the contents of this file. Notice the username at the end.

STEP 2 (Google Cloud Console Method):

  • Login to the Google Cloud Console.
  • Go to "Compute Engine" -> "VM instances".
  • Click on the instance that you want to modify.
  • Click the "EDIT" button to modify the instance.
  • Scroll down to "SSH Keys". Click "Show and edit" under "You have 0 SSH keys".
  • Copy and paste the contents of "keypair.pub" into the box where "Enter entire key data" is displayed.
  • Scroll down to the bottom and click "Save".

STEP 3 - Connect to the instance using SSH: Replace the IP_ADDRESS with the Compute Engine instances external IP address in the following command.

ssh -i keypair development@IP_ADDRESS

This is the correct method to support multiple users connecting to the same Compute Engine instance. Each user has their own keypair and their own username and home directory.

This is also the correct method to provide users with login access to an instance that do not have Google Cloud IAM permissions to the cloud account.

For advanced users, you can use the gcloud compute instances add-metadata command to add the SSH public key to the instance.

You can also add this SSH public key to the Project Metadata which will make this keypair available on all instances within a project.

Upvotes: 2

Related Questions