25

I'm trying to use Google Cloud Source Repository as a remote repository. I followed all the procedures to authenticate with the Google Cloud SDK authentication method that allows me to not use SSH keys (as they say).

The problem is: I always get Permission denied (publickey) fatal: Could not read from remote repository. message when I try git push --all google.

The gcloud command is in my Windows PATH (C:\Users\xxxxx\AppData\Local\Google\Cloud SDK\;) and my user has enough permission as I'm the owner of the project in Google Cloud.

I know this message is usually a simple SSH key problem that can be resolved by adding my public key to the project, but this method is supposed to work without ssh keys, so I would like to learn what I am doing wrong.

Here the 2 first commands I made following the Google Cloud Source Repository procedure:

gcloud init && git config --global credential.https://source.developers.google.com.helper gcloud.cmd
git remote add google ssh://username@gmail.com@source.developers.google.com:2022/p/my-website-project/r/my_website

These 2 worked well.

Maybe someone could help me to find what to do to fix that.

Thank you.

Jecko
  • 403
  • 1
  • 5
  • 10
  • Had the same issue yesterday. I used a different google account before and switched to another. Then the probem came up. It seems the permissions given on my google account caused the problem or some conflict. I deleted the relevant ones and requested those again, e.g. for IntelliJ. Before, I uninstalled gcloud SDK and intellij plugin but these measures might have not been helpful. – chriscross Apr 22 '19 at 14:58
  • I'm getting the same error, except I am using SSH authentication instead of the Google Cloud SDK. – Peet Brits Nov 14 '19 at 09:47

8 Answers8

11

I had the same problem.
These two commands worked well for me too:

gcloud init && git config --global credential.https://source.developers.google.com.helper gcloud.cmd
git remote add google ssh://username@gmail.com@source.developers.google.com:2022/p/my-website-project/r/my_website

But this one didn't work:

git push --all google

I had to edit ~/.ssh/config file to make it work. It solved my problem. I added:

Host source.developers.google.com
    HostName source.developers.google.com
    User username@gmail.com
    IdentityFile ~/.ssh/your_private_key_file_registered_for_the_source_repo

Read more about ~/.ssh/config file here

Kyrylo Bulat
  • 740
  • 8
  • 11
  • What do you mean by `your_private_key_file_registered_for_the_source_repo`? Nobody should register a private key anywhere every for anything. – Kalle Richter Jul 11 '22 at 08:16
11

I had the same problem and none of the solutions I found worked. It turns out Google Cloud Source Repositories didn't like my SSH key. (Maybe the key was too short?) Anyway I tried switching to a ECDSA key and the error went away.

ssh-keygen -t ecdsa -C "myuser@mygmailhost.com"

I had to replace my previous key with the new one in ~/.ssh/config too.

Emmanuel
  • 16,791
  • 6
  • 48
  • 74
  • Emmanuel, could you explain in more detail what you did after generating the new key? – new name Jan 14 '22 at 14:11
  • 1
    @gaefan I followed the instructions here: https://cloud.google.com/source-repositories/docs/authentication#generate_a_key_pair except I didn't use the rsa key type (which is the default). I used the ecdsa type instead. – Emmanuel Jan 22 '22 at 15:37
  • 2
    Worked for me as well. Had a similar resolution when using GitHub due to this, I wonder if it's related: https://github.blog/2021-09-01-improving-git-protocol-security-github/ – Christopher Markieta Jan 23 '22 at 20:17
  • Worked for me, I was facing problem to clone from gcloud source repository. – maruf571 Sep 20 '22 at 08:36
  • 1
    This worked for me as well. I think the default rsa keys are too short https://cloud.google.com/source-repositories/docs/authentication#linux-or-macos RSA (only for keys with more than 2048 bits) – ccook Oct 28 '22 at 14:22
1

I have the same issue on Linux (Mint/Ubuntu) when I was trying to set the remote of an existing repository to Google Cloud Source Repos. This is what it looks like you are attempting. However, this was the empty git repository generated by Expo CLI Quickstart, which had no files or source history at all.

What I did instead was clone the existing repository on Google Cloud Source Repos to my computer, add a dummy file, commit it and push. That worked for me. Hopefully it works for you.

1

Open https://source.developers.google.com/new-password in the browser, log in and follow the instructions displayed. It worked in my case.

0

Having similar issues so tried two things:

1 - suggestion in this topic

Did gcloud init and created and configured ~/.ssh/config but this did not solve the issue.

2 - Then tried the suggestion here and it worked...

How to solve Permission denied (publickey) error when using Git?

0

In my (highly unusual) case, my company adopted Google Workspace. This created a new Google Workspace account with the same name as my original account (original@domain.com) and then changed the name of my original account to [my name]%[company's domain].com@gtempaccount.com.

Since the GCP permissions were associated with the original account, now named [my name]%[company's domain].com@gtempaccount.com, I got the Permission Denied error. The remote url defined in my git config used the original email (original@domain.com), now associated with a newly created Google Workspace account, and that account did not have permissions to access the Cloud Source Repo.

harrolee
  • 495
  • 5
  • 11
0

Add a file named config (no file extension, i.e. no .txt extension) in OpenSSH directory (on Windows it should be in C:\Users\myusername\.ssh) with the following:

Host source.developers.google.com
    HostName source.developers.google.com
    User myemail@mydomain.com
    IdentityFile ~/.ssh/my-private-key-file
Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91
0

this :

git remote add google ssh://username@gmail.com@source.developers.google.com:2022/p/my-website-project/r/my_website

should be this :

git remote add google https://source.developers.google.com/p/[PROJECT_NAME]/r/[REPO_NAME]

  • It seems unlikely this should work in this specific context. – joanis Jan 22 '23 at 15:27
  • That is the URL to use if you don't want to use SSH. first URL is SSH second HTTPS. It is described in the documentation. https://cloud.google.com/source-repositories/docs/adding-repositories-as-remotes – AlienTheDog Jan 23 '23 at 17:57