Connect to Account Using gcloud CLI
Prerequisite: Install gcloud cli
How to authenticate gcp account using gcloud cli
Login in to the account using the below cli command, this command will trigger a browser based authentication
gcloud auth login
After authenticating to the account, let’s connect to the project that we need to work in
gcloud config set project-name
Now we are set with both account and project, but how to confirm this
Yes, below command will help us with the details, this command will list out [default] configuration and project
gcloud config list
Output:-
[accessibility]
screen_reader = False
[core]
account = cloud.scope@company.com
disable_usage_reporting = True
project = first-project
Your active configuration is: [default]
Now we are set with the account and project name, let’s try to list down the virtual machines running in our project.
gcloud compute instances list
How to save multiple accounts configuration?
Assume we are supporting multiple accounts, so we want to login other accounts as well and should be listed under our list with the default configuration
To achieve this, we can create a new configuration for each account and then switch between them.
syntax : gcloud config configurations create/delete/describe/activate/list
Below command will help us to create new configuration
gcloud config configurations create configuration_name
example – gcloud config configurations create my-client
After creating new configuration, Login to the account using auth login and then set the project namegcloud auth login
gcloud config set project-name
After adding the other configuration, run the below command to see all the accounts added in your configuration
gcloud config configurations list
Now we have more than one accounts listed, but at a time only one account can be active, IS_ACTIVE is the column name where we can see which account is currently active in the form of True or False
Bang! We successfully added other account, but wait how can we activate other account
Below command will help us to activate the configuration
gcloud config configurations activate configuration_name
example:- gcloud config configurations activate default
Read More
Most used gsutil commands for Google Cloud Storage
How to create GCP Account for free