github 操作中主机密钥验证失败

问题描述 投票:0回答:1

我有一个调用 shell 脚本的 github actions 设置

  deploy:
    name: Deploy to ECR
    runs-on: ubuntu-latest
    steps:
      - name: Release
        run: |
          chmod +x ./release.sh
          ./release.sh

.release.sh 的内容如下。它的作用是通过 ssh 连接到服务器并运行一些命令:

#!/bin/bash

# SSH connection details
SSH_USER="ubuntu"
SSH_HOST="13.234.201.241"
SSH_PORT="22"
SSH_PRIVATE_KEY="${{ secrets.SSH_PRIVATE_KEY }}"  # Assuming the secret name is SSH_PRIVATE_KEY

    
# Create the SSH private key file
echo "$SSH_PRIVATE_KEY" > ./ssh_private_key
chmod 600 ./ssh_private_key

# SSH command to delete existing Docker container
ssh -i ./ssh_private_key -p "${SSH_PORT}" "${SSH_USER}@${SSH_HOST}" "docker rm -f ${CONTAINER_NAME}"

# SSH command with port forwarding
ssh -i ./ssh_private_key -p "${SSH_PORT}" -L "${LOCAL_PORT}:localhost:${LOCAL_PORT}" "${SSH_USER}@${SSH_HOST}" << EOF
  aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 714116641665.dkr.ecr.us-east-1.amazonaws.com
EOF

# Remove the temporary SSH private key file
rm ./ssh_private_key

但是我无法连接到远程计算机,尽管 github actions 成功运行,但日志表明它无法连接到 ssh 实例。日志是

## FOLLOWING IS LOG Under the 'Release' Step:
Run chmod +x ./release.sh
  chmod +x ./release.sh
  ./release.sh
  shell: /usr/bin/bash -e {0}
  env:
    IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]')/summarizer
    ECR_REPO_NAME: 714116641665.dkr.ecr.us-east-1.amazonaws.com/ml-libraries
./release.sh: line 7: ${{ secrets.SSH_PRIVATE_KEY }}: bad substitution
Host key verification failed.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Host key verification failed.

尽管出现错误(或警告?),github actions 显示此步骤已成功执行。如何解决无法连接到 ssh 机器的问题(正如我所见,显然没有)。

我感觉这个错误可能是由于我定义秘密的方式引起的。SSH_PRIVATE_KEY,但它是正确的,我只是复制粘贴相关的 .pem 文件

请注意,这在我的本地工作正常。将不胜感激任何帮助。

ssh github-actions
1个回答
0
投票

@Azeem 的回答解决了问题,谢谢 Azeem

© www.soinside.com 2019 - 2024. All rights reserved.