我有3台服务器:
werkstation.example.com – >服务器,其中gitlab存储库克隆和更改存储库中的文件
git.example.com – >存储库“tomcat”的gitab服务器
docker.example.com – >服务器,其中的文件将被复制与GIT钩子
我的git钩子:
#!/bin/sh read oldrev newrev refname REPO="[email protected]:michaelv1234/tomcat.git" BRANCH=`echo $refname | sed -n 's/^refs\/heads\///p'` BRANCH_DIR="/home/michael" SSH_DEST="[email protected]" 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 [email protected] /home/michael/master remote: Host key verification failed. To [email protected]:michaelv1234/tomcat.git 0032c02..6e8ef97 master -> master Branch master set up to track remote branch master from origin.
权限文件和目录:
custom_hooks directory: drwxr-xr-x 2 git git 4096 May 27 12:05 custom_hooks post-receive file in custom_hooks: rwxr-xr-x 1 git git 1435 May 27 12:05 post-receive
我已经删除了每个服务器上的“known_hosts”文件,但我仍然收到错误
当初始化SSH连接时,服务器向客户端validation自己。 客户端然后检查密钥是否已经在known_hosts文件中。 如果不是,则会提示用户。 这就是为什么在第一个SSH连接上,你会得到一个提示,询问你是否要接受一个指纹为xyz的密钥。 服务器公钥然后被写入到known_hosts文件中。
如果您从未通过SSH连接到服务器,则不在known_hosts文件中,自动连接将失败。 最简单的方法是以自己的身份通过SSH连接到服务器,并且在提示符下回答“是”。
解决scheme:在Gitlab服务器上:
sudo su - git ssh-keygen ssh-copy-id [email protected] ssh [email protected]