jenkins反对Github给我错误:主机密钥验证失败

时间:2017-03-11 01:57:47

标签: jenkins ssh https

我有一台带有Windows Server 2016和jenkins 2.32.3(最新版本)的虚拟机。

我还安装了一个github插件并设置了ssh密钥。

我做了以下几点:

# update user for git:
git config --global user.name "myuserforgithub"
git config --global user.email myuserforgithubgmail.com


# check ssh:
ls -al ~/.ssh
ssh-keyscan -H github.com > ~/.ssh/known_hosts
ssh-keygen -f ~/.ssh/known_hosts -H -F github.com
ssh-keygen -f ~/.ssh/known_hosts -H -F github.com | grep 'github.com'
ssh-keygen -f ~/.ssh/known_hosts -H -F github.com | wc -l

# create ssh:
ssh-keygen -t rsa -b 4096 -C "myuserforgithub@gmail.com"
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
clip < ~/.ssh/id_rsa.pub

# test ssh:
ssh -T git@github.com

# for working with github:
# create bashrc:
touch ~/.bashrc

# paste following code to bashrc:
env=~/.ssh/agent.env

agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }

agent_load_env

# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi

unset env

# create config:
touch ~/.ssh/config

Host github.com
 IdentityFile ~/.ssh/id_rsa

现在,我使用这些配置在jenkins中创建一个Freestyle项目:

  1. Github项目 - https项目网址https://github.com/myuserforgithub/myfirstjenkinstest.git/

  2. 存储库网址:https://github.com/myuserforgithub/myfirstjenkinstest.git

  3. 凭据 - 我的github凭据

  4. 到目前为止一切都很好。

    现在,当我尝试按如下方式更改为ssh时:

    1. Github项目 - ssh项目网址git@github.com:myuserforgithub/myfirstjenkinstest.git

    2. 存储库网址:git@github.com:myuserforgithub/myfirstjenkinstest.git

    3. 凭据 - 我的github凭据

    4. 我收到如下错误:

      Failed to connect to repository : Command "git.exe ls-remote -h git@github.com:myuserforgithub/myfirstjenkinstest.git HEAD" returned status code 128:
      stdout: 
      stderr: Host key verification failed. 
      fatal: Could not read from remote repository.
      
      Please make sure you have the correct access rights
      and the repository exists.
      

      我正在寻找解决方案,但没有成功..

0 个答案:

没有答案