Cannot get TeamCity to authenticate to GitHub with Default Private Key

家住魔仙堡 提交于 2019-12-07 11:25:36

问题


I'm trying to get TeamCity to build my private GitHub repository. I'm able to successfully get my VCS root to pass the connection test when I explicitly set the path to the key file; however, despite lots of Googling, I can't get it to work when I use the 'Default Private Key' option. I get com.jcraft.jsch.JSchException: Auth fail.

Both my TeamCity server and build agent are running as a user called (gasp) teamcity, and the contents of C:\users\teamcity\.ssh\ include both a config and a key file, where the config is pointing to the key file. My config contains:

Host *
    IdentityFile ~/.ssh/github.key

I've tried a variety of different path styles, both Windows and Unix style, but none seem to work.

Again, it works fine if I use the private key setting and explicitly set the path to the key file, but not when I use the default private key, which I apparently need for my build agent to work.


回答1:


Easiest solution for me was this:

  1. Upload your (OpenSSH) key under your Pipeline's project settings "SSH Keys" (as seen below):

    Look at resource links for OpenSSH info (why/how)

  2. And then in VCS root settings, Update "Authentication Settings" as seen below:

    • note: the username is; "git" (see 3rd resource)
  3. Make sure your "Fetch URL" look something like "git@bitbucket.org:ProjectName/RepositoryName.git" - (Note: Github equivalent is required here)

  4. Add your new key (see 1st resource)

Resources:

  • Here's a link that helped me get to the solution (see section for Putty keygen)
  • TeamCity Docs regarding SSH Keys
  • Username should be "git"



回答2:


Git looks for the .ssh folder by forming a path with %HOMEDRIVE%/%HOMEPATH%. I've found that even though the %USERPROFILE% environment variable is set correctly these are not set. If %HOMEDRIVE% is empty %SYSTEMDRIVE% will be used instead so by default it will look for .ssh folder in c:\ (or whatever your system drive is).

You can check the environment variables an agent has via the agent parameters tab when selecting an agent and what a build is using via the parameters tab of the build.

Solution 1

create .ssh folder in c:

Solution 2

Set environment variables for %HOMEDRIVE% & %HOMEPATH% to match where your userprofile is

Solution 3

git also can use %HOME% environment variable this is the full path i.e. equal %USERPROFILE%




回答3:


default private key also disabled when one use http://... url and not git@...



来源:https://stackoverflow.com/questions/21035820/cannot-get-teamcity-to-authenticate-to-github-with-default-private-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!