【发布时间】:2020-11-06 15:35:33
【问题描述】:
使用 GitLab CI,我想将生产代码推送到远程虚拟主机。
为了连接 SSH,我将密钥对的私钥存储在 GitLab 存储库的变量中。我还将公钥复制到服务器的授权密钥中。这是(部分)我的.gitlab-ci.yml。
image: ubuntu
before_script:
# Setup SSH credentials and known host
- which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 700 ~/.ssh/id_rsa
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/id_rsa
- echo "$SSH_KNOWN_HOSTS"
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
这种方法有效,但我质疑它的安全性。我的私钥这样安全吗?我还能如何实现我正在寻找的结果?
编辑:我特别质疑这种方法在生产环境中的安全性。
【问题讨论】: