Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCE - different username if i use SSH or log in from terminal?

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

like image 575
jason m Avatar asked Apr 22 '17 23:04

jason m


People also ask

How do I SSH into GCP instance?

Connect through a browser from the GCP MarketplaceBrowse to the Google Cloud Platform console and sign in if required using your Google account. Find and select your project in the project list. Select the “Compute -> Compute Engine” menu item. Locate your server instance and select the SSH button.

What is GCP OS login?

OS Login simplifies SSH access management by linking your Linux user account to your Google identity. Administrators can easily manage access to instances at either an instance or project level by setting IAM permissions.

What is SSH in GCP?

SSH-in-browser supports connections from VMs that store SSH keys in metadata, VMs that use OS Login, and VMs that use IAP for TCP forwarding. Each time you connect to a VM by using SSH-in-browser, Compute Engine creates an ephemeral key pair and sets a username for your connection.


2 Answers

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
like image 179
Amir Rahwane Avatar answered Oct 02 '22 15:10

Amir Rahwane


I use this command to fix it on MacOS:

LOGNAME=ubuntu gcloud compute ssh app1
like image 23
cao7113 Avatar answered Oct 02 '22 17:10

cao7113