Gitlab Host key verification failed

May 31, 2016 624 views
Git Ubuntu

I have a custom post-receive hook in Gitlab to SSH and run some SSH commands. But I'm still receiving this error:

michael@client ~/test $ git push -u origin master
Counting objects: 5, done.
Writing objects: 100% (3/3), 267 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Updating remote branch /opt/test/master
remote: Host key verification failed.
   6b276dc..89adda9  master -> master
Branch master set up to track remote branch master from origin.



read oldrev newrev refname

BRANCH=`echo $refname | sed -n 's/^refs\/heads\///p'`

if [ "$newrev" -eq 0 ] 2> /dev/null; then
    # branch is being deleted
    echo "Deleting remote branch $SSH_DEST $BRANCH_DIR/$BRANCH"
    echo ssh $SSH_ARGS "$SSH_DEST" /bin/sh
    ssh $SSH_ARGS "$SSH_DEST" /bin/sh <<-EOF
        cd "$BRANCH_DIR" && rm -rf $BRANCH
    # branch is being updated
    echo "Updating remote branch $SSH_DEST $BRANCH_DIR/$BRANCH"
    ssh $SSH_ARGS "$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; }; }

The host key's are not Changed

1 comment
1 Answer

You are connecting via the SSH protocol. Using SSH, every host has a key. Clients remember the host key associated with a particular address and refuse to connect if a host key appears to change. This prevents man in the middle attacks.

The host key for has changed. If this does not seem fishy to you, you can remove the old key from your local cache using

$ ssh-keygen -R

I strongly encourage you to consider having users authenticate with keys as well. That way, ssh-agentcan store key material for convenience (rather than everyone having to enter her password for each connection to the server), and passwords do not go over the network.

Have another answer? Share your knowledge.