How to register SSH keys in GCP Source Repositories

This post explains how to register SSH Keys for setting up local authentication to interact with Google Cloud Source Repositories.

SSH Authentication

We can use SSH public key authentication to access Google Cloud Source Repositories. Follow below steps to set-up SSH authentication to Google Cloud Source Repositories.


1. Download and set-up Git for windows from https://gitforwindows.org/ .

2. In windows search for Git Bash and open Git Bash.

GCP Source Repositories

2. Enter below command in Git Bash. Replace USER EMAIL with your email address.

   
  ssh-keygen -t ecdsa -C "USER EMAIL"
       

3. On prompt, To accept the default ~/.ssh location, press Enter, otherwise specify a filename.

4. On prompt, leave the passphrase empty and press Enter.

GCP Source Repositories

5. Navigate to ~/.ssh directory and copy the public key from id_ecdsa.pub.

GCP Source Repositories

6. Login to Google Cloud Console and navigate to Source Repositories.

GCP Source Repositories

7. In the Source Repositories click on More Items and than click on Manage SSH Keys.

GCP Source Repositories

8. Click on Register SSH Key.

GCP Source Repositories

9. Provide key name In the Key name field. In the Key field copy the key retrieved in Step 5 and click on Register.

GCP Source Repositories

After registering the SSH keys you should be able access Source Repositories. If you are getting below error than follow the below mentioned steps to fix this issue.

@source.developers.google.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

10. Navigate to ~/.ssh directory, create a file with name config and write following configuration, replace USER EMAIL with your email address.

   
  Host source.developers.google.com
      HostName source.developers.google.com
      User <<USER EMAIL>>
      IdentityFile ~/.ssh/id_ecdsa
      IdentitiesOnly yes
     

GCP Source Repositories

GCP Source Repositories


Category: GCP