Google Cloud Platform Logging in to GCP from command line

0 votes
I was sure it will be simple but couldn't find any documentation or resolution. I'm trying to write a script using gcloud to perform some operations in my GCP instances.

Is there anyway to login/authenticate using gcloud via command line only?

Thanks
Apr 6 in GCP by Rahul
• 3,380 points
72 views

1 answer to this question.

0 votes

You have a couple of options here (depending on what exactly you're trying to do).

The first option is to log in using the --no-launch-browser option. This still requires interaction from a human user, but doesn't require a browser on the machine you're using:

> gcloud auth login --no-launch-browser
Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&prompt=select_account&response_type=code&client_id=32555940559.apps.googleusercontent.com&scope=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%2Fcompute&access_type=offline


Enter verification code: *********************************************
Saved Application Default Credentials.

You are now logged in as [user@example.com].
Your current project is [None].  You can change this setting by running:
  $ gcloud config set project PROJECT_ID

The non-interactive option involves service accounts. The linked documentation explains them better than I can, but the short version of what you need to do is as follows:

  1. Create a service account in the Google Developers Console. Make sure it has the appropriate "scopes" (these are permissions that determine what this service account can do. Download the corresponding JSON key file.

  2. Run gcloud auth activate-service-account --key-file <path to key file>.

Note that Google Compute Engine VMs come with a slightly-different service account; the difference is described here.

answered Apr 6 by Korak
• 5,820 points

Related Questions In GCP

+2 votes
1 answer

How to do SSH in GCP instance from command line?

Hi@akhtar, You can do SSH to GCP instance ...READ MORE

answered Aug 24, 2020 in GCP by MD
• 95,360 points
363 views
+2 votes
1 answer

How to launch one instance on GCP Cloud from command line?

Hi@akhtar, You can compute service in GCP to launch ...READ MORE

answered Aug 24, 2020 in GCP by MD
• 95,360 points
329 views
0 votes
1 answer

How to authenticate with the correct account in GCP from Command Line?

Hi@akhtar, You can check your accounts from the ...READ MORE

answered Sep 24, 2020 in GCP by MD
• 95,360 points
161 views
0 votes
1 answer

How do I get to know my transaction history in Google Cloud Platform?

These are the following steps to look at the transaction history within the Google ...READ MORE

answered Oct 7, 2019 in GCP by Sirajul
• 59,170 points
609 views
0 votes
1 answer
+2 votes
1 answer

How to create a VPC on GCP from command line?

Hi@akhtar, To create a personal network, you need ...READ MORE

answered Aug 24, 2020 in GCP by MD
• 95,360 points
537 views
+2 votes
1 answer

Create a firewall rule on GCP Cloud from command line.

Hi@akhtar, You need to configure GCP Cloud SDK ...READ MORE

answered Aug 24, 2020 in GCP by MD
• 95,360 points
1,013 views
0 votes
1 answer

Google cloud: How to list all service-accounts from all Projects in GCP

Your code sample suggests you want the ...READ MORE

answered Mar 14 in GCP by Korak
• 5,820 points
434 views
0 votes
1 answer

Google Cloud VPN - Egress from GCP to on-premise pricing clarification

IPSec traffic are charged as if the ...READ MORE

answered Mar 20 in GCP by Korak
• 5,820 points
76 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP