【问题标题】:WARNING: UNPROTECTED PRIVATE KEY FILE! using Bitbucket Pipelines and SSH警告:未受保护的私钥文件!使用 Bitbucket 管道和 SSH
【发布时间】:2018-09-06 22:06:04
【问题描述】:

我正在使用 Git 说明并尝试使用 Bitbucket Pipelines 部署到我的远程服务器。

在阅读了一些关于此的帖子并查看其他人的尝试后,我正在使用以下代码:

# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: samueldebruyn/debian-git

pipelines:
    default:
        - step:
            script:
                - umask 077 - echo $MY_SSH_KEY | base64 --decode > ~/.ssh/id_rsa

                - scp -i ~/.ssh/id_rsa -P $SERVER_PORT -r $DIRECTORY_TRANSFER_LIST $USERNAME@$SERVER_IP_ADDRESS:~/site

需要指出的是,环境变量是:

DIRECTORY_TRANSFER_LIST:这是我没有 www 的域。即 domain.co.uk

MY_SSH_KEY:我尝试了公钥和私钥,但似乎没有什么不同。

SERVER_PORT:22

我实际上不确定图片的含义以及为什么此链接在这里,这可能是我的问题?

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/root/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/root/.ssh/id_rsa": bad permissions
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
lost connection

在准备另一篇关于相同错误消息的帖子后,尽管与 Bitbucket Pipelines 无关。建议将 chmod 更改为 400。

所以我 ssh 进入远程服务器并将 id_rsa 的权限更改为 400:

cd ~/.ssh
chmod 400 id_rsa

但是当我重新运行管道时,这并没有任何区别。

我没有做什么?

【问题讨论】:

  • chmod后的错误信息是什么?
  • 和我觉得奇怪的一模一样
  • 那你改权限的文件真的是/root/.ssh/id_rsa吗?

标签: ssh permissions bitbucket bitbucket-pipelines


【解决方案1】:

你写“我 ssh 到远程服务器”——我认为这是问题所在,因为听起来你试图修复项目部署到的服务器上的权限。 SSH 检查 client 端的权限,在您的情况下,它是 Docker 映像中的 SSH 密钥。这意味着您只需在script 中添加chmod,在umaskscp 之间。

【讨论】:

    【解决方案2】:

    我建议您按照以下文档将 SSH 密钥添加到 Pipelines:https://confluence.atlassian.com/bitbucket/use-ssh-keys-in-bitbucket-pipelines-847452940.html

    这将使您无需管理文件权限,更容易轮换密钥,并从您的配置中删除相当混乱的命令。 (您的团队会因此而爱上您!)

    umask 077 - echo $MY_SSH_KEY | base64 --decode > ~/.ssh/id_rsa 方法是 Pipelines 获得适当 SSH 密钥支持之前的一种解决方法。

    【讨论】:

      猜你喜欢
      • 2017-02-22
      • 2016-08-08
      • 2010-09-17
      • 2014-11-10
      • 2020-05-26
      • 2018-07-30
      • 2012-04-22
      • 2012-01-01
      相关资源
      最近更新 更多