繁体   English   中英

Gitlab post-receive hook 主机密钥验证失败

[英]Gitlab post-receive hook Host key verification failed

我有3台服务器:

werkstation.example.com -> server where the gitlab repository is cloned & for changing the files fom the repository
git.example.com -> gitab server with repository "tomcat"
docker.example.com -> server where the files will be copied with git hook

我的 git 钩子:

#!/bin/sh

read oldrev newrev refname

REPO="git@git.example.com:michaelv1234/tomcat.git"
BRANCH=`echo $refname | sed -n 's/^refs\/heads\///p'`
BRANCH_DIR="/home/michael"
SSH_DEST="michael@docker.example.com"

##
# Instantiate the branches on the puppetmaster
if [ "$newrev" -eq 0 ] 2> /dev/null; then
        # branch is being deleted
        echo "Deleting remote branch $SSH_DEST $BRANCH_DIR/$BRANCH"
        echo "$SSH_DEST" /bin/sh
        ssh  "$SSH_DEST" /bin/sh <<-EOF
                cd "$BRANCH_DIR" && rm -rf $BRANCH
        EOF
else
        # branch is being updated
        echo "Updating remote branch $SSH_DEST $BRANCH_DIR/$BRANCH"
        ssh "$SSH_DEST" /bin/sh <<-EOF
                { cd "$BRANCH_DIR/$BRANCH" || mkdir -p "$BRANCH_DIR/$BRANCH" && cd "$BRANCH_DIR/$BRANCH"; } \
                && { git fetch origin && git reset --hard origin/$BRANCH || { git clone "$REPO" ./ && git checkout $BRANCH; }; }
        EOF
fi

但我仍然收到此错误:

michael@werkstation:~/tomcat$ git push -u origin master
Counting objects: 5, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 254 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Updating remote branch michael@docker.example.com /home/michael/master
remote: Host key verification failed.
To git@git.example.com:michaelv1234/tomcat.git
0032c02..6e8ef97  master -> master
Branch master set up to track remote branch master from origin.

我已经删除了每台服务器上的“known_hosts”文件,但我仍然收到错误

解决方案:在 Gitlab 服务器上:

sudo su - git
ssh-keygen
ssh-copy-id michael@docker.example.com
ssh michael@docker.example.com

docker.example.com 上的 SSH 密钥是否更改?

您收到remote: Host key verification failed. 错误,因为 docker.example.com 机器的 SSH 主机密钥与 git.example.com 上known_hosts文件中包含的密钥不匹配。

在 git.example.com 机器上搜索known_hosts文件,看看它是否包含docker.example.com的条目。 如果找到条目,请删除ssh-keygen -R docker.example.com >> /path/to/known_hosts试该操作(或者运行ssh-keygen -R docker.example.com >> /path/to/known_hosts以更新该主机的密钥)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM