【问题标题】:Why doesn't my SSH key work with Google Cloud Source repositories?为什么我的 SSH 密钥不能用于 Google Cloud Source 存储库?
【发布时间】:2023-01-08 04:24:47
【问题描述】:

我已经用 github、gitlab 和其他 repos 完成了这个......但我正在尝试使用云源存储库设置一个 ssh 密钥

git clone ssh://<user_name>@<domain>.com@source.developers.google.com:2022/p/<project-id>/r/omni-orchestrator

它给了我一个:

Cloning into 'omni-orchestrator'...
Warning: Permanently added the ECDSA host key for IP address '[<Some_IP>]:2022' to the list of known hosts.
<user_name>@<domain>.com@source.developers.google.com: Permission denied (publickey).
fatal: Could not read from remote repository.

我可以通过gcloud 进行克隆,因此我拥有访问存储库所需的权限...只是不使用 ssh。

$ gcloud source repos clone omni-orchestrator --project=<project_id>
Cloning into '/home/<user>/workspaces/<client>/gcp/omni-orchestrator'...
warning: You appear to have cloned an empty repository.
Project [<project_id>] repository [omni-orchestrator] was cloned to [/home/<user>/workspaces/<client>/gcp/omni-orchestrator].

我使用this guide 创建了几个密钥,并更改了密钥名称。

另外,这里是我根据一些类似的帖子和一些有用的建议所做的一些尝试。

~/.ssh中创建config文件指定使用的私钥

Host gitserv
    Hostname source.developers.google.com
    IdentityFile ~/.ssh/<user_name>_<domain>_com
    User <user_name>@<domain>.com

设置变量:GIT_SSH_COMMAND

<user_name>@AWESOME-<user_name>3:~/workspaces/<domain>/gcp$ export GIT_SSH_COMMAND='ssh -v -i /home/<user_name>/.ssh/<user_name>_<domain>_com -o IdentitiesOnly=yes'
<user_name>@AWESOME-<user_name>3:~/workspaces/<domain>/gcp$ git clone ssh://<user_name>@<domain>.com@source.developers.google.com:2022/p/<project_id>/r/omni-orchestrator
fatal: destination path 'omni-orchestrator' already exists and is not an empty directory.
<user_name>@AWESOME-<user_name>3:~/workspaces/<domain>/gcp$ cd ..
<user_name>@AWESOME-<user_name>3:~/workspaces/<domain>$ git clone ssh://<user_name>@<domain>.com@source.developers.google.com:2022/p/<project_id>/r/omni-orchestrator
Cloning into 'omni-orchestrator'...
OpenSSH_7.6p1 Ubuntu-4ubuntu0.7, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /home/<user_name>/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to source.developers.google.com [74.125.133.82] port 2022.
debug1: Connection established.
debug1: identity file /home/<user_name>/.ssh/<user_name>_<domain>_com type 2
debug1: key_load_public: No such file or directory
debug1: identity file /home/<user_name>/.ssh/<user_name>_<domain>_com-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.7
debug1: Remote protocol version 2.0, remote software version Go
debug1: no match: Go
debug1: Authenticating to source.developers.google.com:2022 as '<user_name>@<domain>.com'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:AGvEpqYNMqsRNIviwyk4J4HM0lEylomDBKOWZsBn434
debug1: Host '[source.developers.google.com]:2022' is known and matches the ECDSA host key.
debug1: Found key in /home/<user_name>/.ssh/known_hosts:7
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: ECDSA SHA256:z7IqQohzIjyZVpxTTGKams9JxhquHb9pYhtnWMfgkuE /home/<user_name>/.ssh/<user_name>_<domain>_com
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
<user_name>@<domain>.com@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.

【问题讨论】:

    标签: git google-cloud-platform google-cloud-source-repos


    【解决方案1】:

    来自gcloud Clone using SSH,“用户”应该是电子邮件

    git clone ssh://[EMAIL]@source.developers.google.com:2022/p/[PROJECT_ID]/r/[REPO_NAME]
    

    您在您的~/.ssh/config 中找到了电子邮件,但您从未使用过您的配置主机条目“gitserv”。
    并且说条目中缺少Port 2022

    相反,您定义了一个 GIT_SSH_COMMAND='ssh -v -i ...

    URL 应该改为:

    git clone gitserv:p/<project_id>/r/omni-orchestrator
    

    如果仍然失败,请检查先决条件:

    1. 确保your key is registered
    2. 您必须有一个repository in Cloud Source Repositories
    3. 您必须有permissions to interact with the repository
    4. 要克隆的存储库不能有限制名称,例如 All-UsersAll-Projects

      第 1 点和第 3 点与您的情况相关。

    【讨论】:

      【解决方案2】:

      我的修复是在我的 OpenSSH 目录(在 Windows 上它应该在 C:Usersmyusername.ssh)中添加一个名为 config 的文件(没有文件扩展名,即没有 .txt 扩展名),其中包含以下内容:

      Host source.developers.google.com
          HostName source.developers.google.com
          User myemail@mydomain.com
          IdentityFile ~/.ssh/my-private-key-file
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-17
        • 1970-01-01
        相关资源
        最近更新 更多