Cyberithub

How to Add a Service Accounts Key in Google Cloud in 7 Easy Steps

Advertisements

In this article, we will see how to add a service accounts key in Google Cloud in 7 Easy Steps. Many times you might got a scenario where you need to access Google Cloud resources programmatically or deploy or run some piece of code using a script or program. All these tasks can only be accomplished if you generate and use a Service Accounts Key or else GCP won't allow to perform any operation on its resources. Here we are going to look all the steps in detail required to add a Service Account Key in GCP. More on Google Cloud docs.

How to Add a Service Accounts Key in Google Cloud in 7 Easy Steps

How to Add a Service Accounts Key in Google Cloud

Also Read: Step by Step Guide to Configure Jenkins Master-Slave Setup on GCP

Advertisements

Step 1: Prerequisites

a) You should have a valid Google Email ID and Password.

b) You should have access to Create Service Accounts and add Keys.

Advertisements

Step 2: Go to Service Accounts

In the first step, you need to go to Service Accounts from Google Cloud Dashboard as shown below. Click on IAM & Admin->Service Accounts.

How to Add a Service Accounts Key in Google Cloud in 7 Easy Steps 2

Step 3: Create Service Account

You will see a screen like below. Here you need to click on Create Service Account.

Advertisements

How to Add a Service Accounts Key in Google Cloud in 7 Easy Steps 3

Then provide the Service account name and Service Account ID as shown below. For our example we are using sample-account as Service Account name and sample-account@sample-project-308612.iam.gserviceaccount.com as Service Account ID. Once given, click on Create.

How to Add a Service Accounts Key in Google Cloud in 7 Easy Steps 4

Step 4: Add Role(Optional)

Here you can see an optional step to Grant this Service Account access to perform some specific tasks. For example, to run cloud build script we need to assign Cloud Build Service Account Role as shown below. If you don't want to assign, then you can just leave it and Click on Continue.

Advertisements

How to Add a Service Accounts Key in Google Cloud in 7 Easy Steps 5

Step 5: Grant Users Access to this Service Account(Optional)

This is also an optional step where you can Grant User access to this service account. For now, we are leaving it blank and directly Clicking on Done.

How to Add a Service Accounts Key in Google Cloud in 7 Easy Steps 6

This will create our required Service Account as shown below. You can also notice from below screen that as of now there are no keys added to this account. So our next step is to Create and add a key here.

How to Add a Service Accounts Key in Google Cloud in 7 Easy Steps 7

Step 6: Click on Manage Keys

To create a new key, you need to select the earlier created Service account and then click on 3 dot showing at the extreme right end. Here you need to select Manage Keys option as shown below.

How to Add a Service Accounts Key in Google Cloud in 7 Easy Steps 8

After clicking on Manage Keys, you will get below option to add key. Once you click the down arrow showing next to Add Key option, you will see an option to Create new key. You need to click on this option.

How to Add a Service Accounts Key in Google Cloud in 7 Easy Steps 9

Step 7: Create JSON/P12 Key

Finally, you need to select the type of key you need to generate. Since here we need to generate private key in JSON format so we will click the JSON radio button and then click on Create. It will download the private key in your local system in .json format. Now you can go ahead and use this key to access  Google Cloud Resources programmatically.

How to Add a Service Accounts Key in Google Cloud in 7 Easy Steps 10

Leave a Comment