尝试将 SSH 密钥添加到 GitLab CI 管道时出现“加载密钥“(stdin)”时出错:libcrypto 中出现错误”

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

我正在尝试将 SSH 密钥添加到 GitLab 管道。 SSH 密钥采用 ED25519 格式,并保存为组环境变量和 GitLab 中的文件。当我在 GitLab 中保存 SSH 密钥的内容时,我点击“返回”以添加另一行。当我尝试将 SSH 密钥加载到管道中时,我得到了

Error loading key "(stdin)": error in libcrypto
。我还尝试使用
echo >> "$PIPELINE_SSH_KEY"
在管道 YAML 中手动添加新行,但遇到了相同的错误。我遵循 GitLab 文档 中关于添加换行符的建议,但它不起作用。我需要以不同的方式添加换行符吗?

这是我的 GitLab YAML 的一部分:

script:
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
    - eval $(ssh-agent -s)
    - echo >> "$PIPELINE_SSH_KEY"
    - echo "$PIPELINE_SSH_KEY" | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - ssh-keyscan $CI_SERVER_HOST >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
bash gitlab gitlab-ci
1个回答
0
投票

过去几天我自己也在努力解决这个问题。所有文档或罕见的博客解决方案都不起作用。我不会声称这是正确的方法,但我最终这样做了:

before_script:
  - apt-get update -qq
  - apt-get install -qq git
  - 'which ssh-agent || ( apt-get -qq install openssh-client)'
  - eval $(ssh-agent -s)
  - chmod 600 "$SSH_KEY"
script:
  - ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no [email protected] "cd sites/target_dir && git pull"
© www.soinside.com 2019 - 2024. All rights reserved.