Skip to content

Commit bc74e7b

Browse files
committed
Fix SSH host key checking in deployment workflow
1 parent 3f7e035 commit bc74e7b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

.github/workflows/deploy.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,23 @@ jobs:
100100
- name: Add server to known hosts
101101
run: |
102102
mkdir -p ~/.ssh
103-
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
103+
chmod 700 ~/.ssh
104+
ssh-keyscan -H ${{ secrets.SSH_HOST }} 2>/dev/null >> ~/.ssh/known_hosts || echo "Warning: ssh-keyscan failed, will use StrictHostKeyChecking=accept-new"
105+
chmod 644 ~/.ssh/known_hosts
104106
105107
- name: Deploy to ${{ env.ENVIRONMENT }}
106108
run: |
107109
DEPLOY_PATH="${{ env.DEPLOY_PATH }}"
108110
PM2_APP_NAME="${{ env.PM2_APP_NAME }}"
109111
ECOSYSTEM_FILE="${{ env.ECOSYSTEM_FILE }}"
110112
111-
# Copy files to server
112-
scp -r deploy.tar.gz ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:$DEPLOY_PATH/
113+
# Copy files to server (accept new host keys automatically)
114+
scp -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=~/.ssh/known_hosts \
115+
-r deploy.tar.gz ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:$DEPLOY_PATH/
113116
114-
# SSH into server and deploy
115-
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "bash -s" << EOF
117+
# SSH into server and deploy (accept new host keys automatically)
118+
ssh -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=~/.ssh/known_hosts \
119+
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "bash -s" << EOF
116120
set -e
117121
cd $DEPLOY_PATH
118122

0 commit comments

Comments
 (0)