初心 - gitlab-ci
type: channel
link: https://www.mayanpeng.cn/tag/gitlab-ci/
items: gitlab-ci利用rsync和sshpass部署项目时报错“Host key verification failed”

gitlab-ci利用rsync和sshpass部署项目时报错“Host key verification failed”
type: item
date: 2023-11-11T17:02:10+08:00
description: 由于是内部私有项目，为了方便连接ssh时，使用了密码.gitlab-ci.ymlstages: - deploy # 部署 deploy: stage: deploy image: alpine:latest variables: TARGET_DIR: /opt/1panel/apps/openresty/openresty/www/sites/scripts/index/ before_script: - apk update - apk add openssh - apk add rsync - apk add sshpass - mkdir -p ~/.ssh - chmod 700 ~/.ssh - echo "StrictHostKeyChecking no" >> ~/.ssh/known_hosts - export SSHPASS=$SERVER_PASSWORD script: - sshpass -e rsync -azv --delete --exclude='.*' . $SERVER_USER@$SERVER_HOST:$TARGET_DIR rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH 报错信息：Host key verification failed. rsync error: unexplained error (code 255) at rsync.c(713) [sender=3.2.5] ERROR: Job failed: exit code 6解决添加-e "ssh -o StrictHostKeyChecking=no"选项修改同步命令为sshpass -e rsync -azv -e "ssh -o StrictHostKeyChecking=no" --delete --exclude='.*' . $SERVER_USER@$SERVER_HOST:$TARGET_DIR