我们在 jenkins 上使用 SSH 密钥从远程 Git 进行克隆。效果很好。我们使用 git 插件,使用 SSH 凭据,并且能够克隆存储库。
但是当我们在稍后阶段执行以下命令时,它会失败:
git pull origin master
Run Code Online (Sandbox Code Playgroud)
它抱怨:
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
该命令似乎不再使用我们的 SSH 凭据。我们如何使用 git CLI 来保存我们的 SSH 凭据?
我已经在这里看到了答案,但这似乎是我们面临的另一种情况。
+
cat .git/config
[core]
repositoryformatversion = 0
filemode = true
logallrefupdates = true
[remote "origin"]
url = ssh://git@xxx/test-repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
Run Code Online (Sandbox Code Playgroud)
小智 5
首先检查您现有的 SSH 密钥:
打开 Git Bash。
输入ls -al ~/.ssh以查看是否存在现有 SSH 密钥:
$ ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist
Run Code Online (Sandbox Code Playgroud)
检查目录列表以查看您是否已有公共 SSH 密钥。
如果存在现有 SSH 密钥,请测试您的 SSH 连接:
打开 Git Bash。
输入以下内容:
$ ssh -T git@github.com
# Attempts to ssh to GitHub
Run Code Online (Sandbox Code Playgroud)
您可能会看到以下警告之一:
The authenticity of host 'github.com (IP ADDRESS)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
The authenticity of host 'github.com (IP ADDRESS)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?
Run Code Online (Sandbox Code Playgroud)
验证您看到的消息中的指纹是否与步骤 2 中的消息之一匹配,然后键入 yes:
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.
Run Code Online (Sandbox Code Playgroud)
验证生成的消息是否包含您的用户名。如果您收到“权限被拒绝”消息,请参阅“错误:权限被拒绝(公钥)”。
如果上述过程不起作用:
生成 git 存储库的 SSH 密钥步骤:
打开 Git Bash。
粘贴下面的文本,替换为您的 GitHub 电子邮件地址。
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Run Code Online (Sandbox Code Playgroud)
这将使用提供的电子邮件作为标签创建一个新的 ssh 密钥。
Generating public/private rsa key pair.
Run Code Online (Sandbox Code Playgroud)
当系统提示您“输入要保存密钥的文件”时,请按 Enter。这接受默认文件位置。
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
Run Code Online (Sandbox Code Playgroud)
在出现提示时,键入安全密码。有关更多信息,请参阅“使用 SSH 密钥密码”。
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
Run Code Online (Sandbox Code Playgroud)
添加新的 SSH 密钥到您的 git 存储库,请访问此处,
https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
| 归档时间: |
|
| 查看次数: |
11227 次 |
| 最近记录: |