我使用GitLab进行CI/CD,想要通过ssh连接我的树莓派进行部署。我生成了一对新的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
更改私钥的权限。之后重新启动了树莓派。但是仍然不起作用。
/dev/fd/63
是使用 Bash 进程替换 (ssh-add <(echo "$SSH_PRIVATE_KEY")
) 时获取管道的名称。您需要更改它,或编写一个修复程序来ssh-add
,只有在读取常规文件而不是管道时才检查权限。 - Toby Speight