0

I am trying to clone a project from gitlab using GO CI/CD pipeline. Steps i did as below,

  1. I already have ssh key which i have added to gitlab.
  2. tried to clone from my local machine and i am able to clone using "git clone" command
  3. I also tried on the Go-agent server using command "git clone" and project is cloned there.
  4. After clone the project I opened the ssh folder and "known_hosts" file is modified with some key. So i have placed the ssh folder at "C:\Windows\System32\config\systemprofile" location because GO- CD pipeline looks there only.
  5. But whenever i am trying to test the connection of pipeline it says access denied. below is the error

:

Repository ssh://git@gitlab.demo.com/exampleproject/someproject.git not found! : 
Error performing command: --- Command ---
git ls-remote ssh://git@gitlab.demo.com/exampleproject/someproject.git
--- Environment ---
{}
--- INPUT ----


--OUTPUT ---

--- ERROR ---
STDERR: Host key verification failed.
STDERR: fatal: Could not read from remote repository.
STDERR: 
STDERR: Please make sure you have the correct access rights
STDERR: and the repository exists.

I also tried running command ssh -T git@gitlab.demo.com but it shows "Permission denied (publickey).". Can anyone tell me why? what configuration i am missing?

marcolz
  • 2,880
  • 2
  • 23
  • 28
user2768132
  • 460
  • 4
  • 11
  • 26

1 Answers1

0

If you have created a key using the default name of id_rsa, try copying it to C:\Windows\SysWOW64\config\systemprofile.ssh (https://startbigthinksmall.wordpress.com/2012/04/26/how-to-authorize-local-system-account-for-openssh/).

If that doesn't work after restarting your service, or if you think you will need to use more than one identity, the following might be helpful:

I assume restarting your Go-CD server service didn't work and that you are running your Go Server service using the default Local System account. I prefer to run using a domain account as that helps with some tricky permissions issues and this type of configuration. Take a look at this answer first: .ssh/config file for windows (git)

If you are running under a service account, your RSA keys are typically written to ~/.ssh/ - which likely translates to: C:/Users/your-account/.ssh. If this folder doesn't exist, open a command window in admin mode, cd to your account folder and run mkdir .ssh.

When Go-CD makes a connection to a Git repository using SSH, it uses git commands which in turn call ssh commands. With all these layers there are a number of approaches to configuring what identity or identities to use. An article to read first is (https://medium.com/@pinglinh/how-to-have-2-github-accounts-on-one-machine-windows-69b5b4c5b14e) Notice how the sshCommand overrides which identity git will use by specifying the file path to your rsa file.

Instead of editing the git configuration directly, my opinion is that editing the global ssh configuration will better handle multiple identities/keys and will be easier for Go-CD to handle. See https://www.ssh.com/ssh/config/. By default the ssh configuration file is located at ~/.ssh/config. If you don't have one, create a text file named config without any extension. Edit the file and add an entry that specifies the path to your Identity File (RSA Key) or files. For example (https://superuser.com/questions/366649/ssh-config-same-host-but-different-keys-and-usernames):

  Host github_username1
    Hostname github.com
    User git
    IdentityFile ~/.ssh/rsa_1
  Host github_username2
    Hostname github.com
    User git
    IdentityFile ~/.ssh/rsa_2

This establishes an host alias you can use for your material. So, instead of using git@gitlab.com/pathtorepo, you would use git@github_username2/pathtorepo if you were using the second host shown above.

Always give your Go-CD service a bounce after making changes, just in case.

Smallwood19
  • 61
  • 1
  • 1
  • 9