15
votes

I created a new project with nothing in it.

When I created my first micro instance I did the following

  1. Connect to it using the browser window SSH. I see:

    user_name@instance-1:~$

  2. If I connect using the gcloud command:

    gcloud compute --project "projectname-165421" ssh --zone "us-east1-b" "instance-1"

    I am brought to:

    username@instance-1:~$

Why is this happening, and how do I resolve it?

This is creating two separate users which is creating a great deal of confusion for me!

Thank you

3

3 Answers

18
votes

By default, the cloudSDK will try to connect using the user running the command.

If you look at the docs, It says you can specify the username like you would, with your default ssh client.

Meaning on your computer:

gcloud compute --project "projectname-165421" ssh --zone "us-east1-b" "user_name@instance-1"

Alternatively, switch user in the browser window SSH:

sudo su username
1
votes

In answer to some of the comments: yes, you can change the default username. This is stored under the environment variable $USER. You can view the current value of this variable by running in your local terminal:

echo $USER

You can set the value of this variable to the default user you would like, by running the following (assuming you are using any of bash/zsh):

export USER=the_new_default_user

For example, if the new desired default user is "pablo" then:

export USER=pablo

Now, every time you run the following command to ssh in your instance, you'll ssh into pablo:

gcloud compute ssh MY_INSTANCE

I hope this helps!

1
votes

I use this command to fix it on MacOS:

LOGNAME=ubuntu gcloud compute ssh app1