我将GitLab用于CI / CD,我想通过SSH部署到我的Raspberry Pi。
我生成了一个新的ED25519 SSH
密钥对,将私钥添加到了变量中,并使用了公共密钥来部署了密钥。
我的gitlab-ci.yaml文件如下:
deployment:
stage: deploy
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- eval $(ssh-agent -s)
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- apt-get install rsync
script:
- ssh pi@IP-ADDRESS "cd dockerproject2 && mkdir test"
tags:
- ssh
这是我部署阶段的输出:
$ which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
/usr/bin/ssh-agent
$ mkdir -p ~/.ssh
$ chmod 700 ~/.ssh
$ eval $(ssh-agent -s)
Agent pid 2805
$ [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
$ ssh-add <(echo "$SSH_PRIVATE_KEY")
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0660 for '/dev/fd/63' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
ERROR: Job failed: exit status 1
我尝试使用$ chmod 600 private_key_name
和$ chmod 0644 private_key_name
更改私钥的许可。之后,我重新启动了Raspberry Pi。但是什么都没有。
答案 0 :(得分:1)
我找到了解决方案。
根本无法使用如下命令:ssh-add <(echo "$SSH_PRIVATE_KEY")
它必须看起来像这样:echo "$SSH_PRIVATE_KEY" | ssh-add -