[英]Get Permission denied (publickey) for Git push to Google Cloud Source Repository with Google Cloud SDK authentication method on Windows 10
I'm trying to use Google Cloud Source Repository as a remote repository.我正在尝试使用 Google Cloud Source 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).我按照所有程序使用 Google Cloud SDK 身份验证方法进行身份验证,该方法允许我不使用 SSH 密钥(正如他们所说)。
The problem is: I always get Permission denied (publickey) fatal: Could not read from remote repository.
问题是:我总是得到Permission denied (publickey) fatal: Could not read from remote repository.
message when I try git push --all google
.当我尝试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. gcloud
命令在我的 Windows PATH ( C:\Users\xxxxx\AppData\Local\Google\Cloud SDK\
;) 中,我的用户有足够的权限,因为我是 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.我知道这个消息通常是一个简单的 SSH 密钥问题,可以通过将我的公钥添加到项目中来解决,但是这种方法应该在没有 ssh 密钥的情况下工作,所以我想了解我做错了什么。
Here the 2 first commands I made following the Google Cloud Source Repository procedure:这是我按照 Google Cloud Source Repository 程序执行的前 2 个命令:
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.谢谢你。
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.我必须编辑~/.ssh/config文件才能使其工作。 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在此处阅读有关~/.ssh/config文件的更多信息
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.事实证明 Google Cloud Source Repositories 不喜欢我的 SSH 密钥。 (Maybe the key was too short?) Anyway I tried switching to a ECDSA key and the error went away. (也许密钥太短了?)无论如何,我尝试切换到 ECDSA 密钥并且错误消失了。
ssh-keygen -t ecdsa -C "myuser@mygmailhost.com"
I had to replace my previous key with the new one in ~/.ssh/config too.我也不得不用 ~/.ssh/config 中的新密钥替换我以前的密钥。
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.当我尝试将现有存储库的远程设置为 Google Cloud Source Repos 时,我在 Linux(Mint/Ubuntu)上遇到了同样的问题。 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.但是,这是Expo CLI Quickstart生成的空 git 存储库,它根本没有文件或源历史记录。
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.我所做的是将 Google Cloud Source Repos 上的现有存储库克隆到我的计算机,添加一个虚拟文件,提交并推送。 That worked for me.这对我有用。 Hopefully it works for you.希望它对你有用。
Having similar issues so tried two things:有类似的问题所以尝试了两件事:
1 - suggestion in this topic 1 - 本主题中的建议
Did gcloud init and created and configured ~/.ssh/config but this did not solve the issue.是否 gcloud init 并创建和配置了 ~/.ssh/config 但这并没有解决问题。
2 - Then tried the suggestion here and it worked... 2 - 然后在这里尝试了这个建议,它奏效了......
How to solve Permission denied (publickey) error when using Git? 使用 Git 时如何解决 Permission denied (publickey) 错误?
In my (highly unusual) case, my company adopted Google Workspace.在我(非常不寻常的)案例中,我的公司采用了 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
.这创建了一个与我的原始帐户 ( original@domain.com
) 同名的新 Google Workspace 帐户,然后将我的原始帐户的名称更改为[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.由于 GCP 权限与原始帐户相关联,现在名为[my name]%[company's domain].com@gtempaccount.com
,我收到 Permission Denied 错误。 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.我的 git 配置中定义的远程 url 使用了原始电子邮件 ( original@domain.com
),现在与新创建的 Google Workspace 帐户相关联,并且该帐户没有访问 Cloud Source Repo 的权限。
Open https://source.developers.google.com/new-password
in the browser, log in and follow the instructions displayed.在浏览器中打开https://source.developers.google.com/new-password
,登录并按照显示的说明进行操作。 It worked in my case.它在我的情况下有效。
Add a file named config
(no file extension, ie no .txt
extension) in OpenSSH directory (on Windows it should be in C:\Users\myusername\.ssh
) with the following:在 OpenSSH 目录(在 Windows 上,它应该在C:\Users\myusername\.ssh
)添加一个名为config
的文件(没有文件扩展名,即没有.txt
扩展名),内容如下:
Host source.developers.google.com
HostName source.developers.google.com
User myemail@mydomain.com
IdentityFile ~/.ssh/my-private-key-file
this:这个:
git remote add google ssh://username@gmail.com@source.developers.google.com:2022/p/my-website-project/r/my_website git 远程添加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] git 远程添加谷歌https://source.developers.google.com/p/[PROJECT_NAME]/r/[REPO_NAME]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.