#
Connect to GCP using the Google Cloud CLI
This tutorial explains how we can connect to GCP using the Google Cloud CLI on Windows.
Once you have installed the GCP CLI,
the next step is to open a Command Prompt Window and run gcloud auth login
.
gcloud auth login
The browser will open automatically, and you will log to your GCP account.
After that you will see something like this:
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=TD5SS8fu7n1Lki7DNoTkrv8z7oloEo&access_type=offline&code_challenge=e9P1wOQIw3XGt-8X9CNdL_oLd3OWrU8-BAKq0h1cMzw&code_challenge_method=S256
You are now logged in as [xxxxx.xxxxxxx@gmail.com].
Your current project is [fluted-layout-376110]. You can change this setting by running:
$ gcloud config set project PROJECT_ID
Sometimes, we cannot access a web browser from the environment where you run gcloud auth login
command.
In this case, we need to run the gcloud auth login --no-launch-browser
command and we will see
something like this:
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fsdk.cloud.google.com%2Fauthcode.html&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=nSgPcREw2cMKSEdHTlQPBRBe0l6ufZ&prompt=consent&access_type=offline&code_challenge=Y_lJ-kMgcaYjjSmQC2O1hlmyUuCtD1-WS_LAXrpS3ps&code_challenge_method=S256
Enter authorization code:
We need to copy the link in a browser. After the connection to GCP we will receive an authorization code in the browser. We copy this code into the Command Prompt windows, and we can see something like this:
Enter authorization code: 4/0AWtgzh7OgZ7JB92loFlwyQYbI4qim3JJrlCWyU2MeQ-gVsgj6hSyMlirBLPvtMaVTIJNdw
You are now logged in as [paul.tomoiu@gmail.com].
Your current project is [fluted-layout-376110]. You can change this setting by running:
$ gcloud config set project PROJECT_ID
At this point you can run commands on the GCP Cloud.
You can test the login using a command like this one if we want :
gcloud projects list
In my case the result is this:
PROJECT_ID NAME PROJECT_NUMBER
fluted-layout-376110 My First Project 476731510945