skip to Main Content

I’ve done this with github, gitlab and other repos… But I am trying to set an ssh key with cloud source repositories

git clone ssh://<user_name>@<domain>[email protected]:2022/p/<project-id>/r/omni-orchestrator

and it is giving me a :

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>[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

I am able to clone via gcloud, so I have the required permissions to acces the repo… just not with 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].

I created several keys using this guide, and changing the key name.

Also, here are a few attempts I made according to a few similar posts and some helpful advice.

Create config file in ~/.ssh to specify the used private key

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

Set variable :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>[email protected]: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>[email protected]: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: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] 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>[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

2

Answers


  1. From gcloud Clone using SSH, the "user" is supposed to be the email

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

    You did you the email in your ~/.ssh/config, but you never used your config Host entry ‘gitserv‘.
    And said entry is missing a Port 2022 in it.

    Instead you defined a GIT_SSH_COMMAND='ssh -v -i ...

    The URL should be instead:

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

    If that still fails, then check the pre-requisites:

    1. make sure your key is registered
    2. You must have a repository in Cloud Source Repositories.
    3. You must have permissions to interact with the repository.
    4. The repository to be cloned cannot have a restricted name such as All-Users or All-Projects.

    Point 1. and 3. are relevant in your case.

    Login or Signup to reply.
  2. The fix for me was to add a file named config (no file extension, i.e. no .txt extension) in my OpenSSH directory (on Windows it should be in C:Usersmyusername.ssh) with the following:

    Host source.developers.google.com
        HostName source.developers.google.com
        User [email protected]
        IdentityFile ~/.ssh/my-private-key-file
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search