【问题标题】:Bitbuket pipeline - how to set sshBitbucket 管道 - 如何设置 ssh
【发布时间】:2019-06-06 01:54:08
【问题描述】:

当我的管道运行时,我收到以下错误:

debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/config
debug1: key_load_private_type: incorrect passphrase supplied to decrypt private key
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
lost connection

这是我的 .yml 文件:

image: maven:3.3.9

pipelines:
  default:
    - step:
        caches:
          - maven
        name: Build
        script: # Modify the commands below to build your repository.
          - echo "Build Start"
          - mvn package
          - echo $BUILD_DIR
          - mv target/**.jar target/transpoDirect.jar
        artifacts:
          - target/**.jar
    - step:
        name: Deploy
        image: maven:3.3.9
        script:
           - ls -la .
           - scp -i ~/.ssh/config -P 7822 -v -o StrictHostKeyChecking=no target/*.jar root@$hostName:/var/transpoDirect/.
           - ssh -p 7822 -i ~/.ssh/config -v -o StrictHostKeyChecking=no root@$hostName sudo service transpoDirect restart

我尝试的是 chmod ~/.ssh 文件夹和那里的文件到 777

hostName 变量在存储库的设置中设置。

重新生成密钥。粘贴在远程服务器的authorize_keys文件中,但我仍然得到同样的错误

authorized_keys 的位置:

================================================ ==================

这是有效的:

  1. 从 bitbucket 的管道中删除了 SSH 密钥。
  2. 使用 ssh-keygen 在远程服务器上生成 SSH 密钥
  3. 上述命令使用默认值,不设置密码。
  4. 生成密钥的默认位置是:/root/.ssh
  5. .ssh 文件夹被隐藏。使用 winSCP,您可以取消隐藏隐藏文件夹。
  6. 从远程服务器复制 id_rsa.pub 的内容并粘贴到 bitbucket 的 SSH 中。
  7. 使用 /root/.ssh 中的 id_rsa.pub 的内容创建了 authorized_keys
  8. 从远程服务器复制 id_rsa 的内容并粘贴到 bitbucket 的 SSH 中。
  9. 这会将 jar 复制到远程服务器:

    • scp -i /root/.ssh -4 -P 7822 -v -o StrictHostKeyChecking=no target/*.jar root@$hostName:/var/transpoDirect/。
  10. 这会重新启动服务,如下所述:https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html

    • ssh -4 -p 7822 -i /root/.ssh -v -o StrictHostKeyChecking=no root@$hostName sudo service transpoDirect restart

【问题讨论】:

    标签: ssh bitbucket bitbucket-pipelines


    【解决方案1】:

    这是有效的:

    1. 从 bitbucket 的管道中删除了 SSH 密钥。
    2. 使用 ssh-keygen 在远程服务器上生成 SSH 密钥
    3. 上述命令使用默认值,不设置密码。
    4. 生成密钥的默认位置是:/root/.ssh
    5. .ssh 文件夹被隐藏。使用 winSCP,您可以取消隐藏隐藏文件夹。
    6. 从远程服务器复制 id_rsa.pub 的内容并粘贴到 bitbucket 的 SSH 中。
    7. 使用 /root/.ssh 中的 id_rsa.pub 的内容创建了 authorized_keys
    8. 从远程服务器复制 id_rsa 的内容并粘贴到 bitbucket 的 SSH 中。
    9. 这会将 jar 复制到远程服务器:

      scp -i /root/.ssh -4 -P 7822 -v -o StrictHostKeyChecking=no target/*.jar root@$hostName:/var/transpoDirect/。

    10. 这会重新启动服务,如下所述:https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html

      ssh -4 -p 7822 -i /root/.ssh -v -o StrictHostKeyChecking=no root@$hostName sudo service transpoDirect restart


    补充说明: 该文件应放在 $HOME/.ssh/authorized_keys 您可以通过 eval echo "$HOME" 检查 $HOME 的位置 另外,需要理解的是 id_rsa 是私有文件 - 这意味着该文件不被共享,但 id_rsa.pub 是公共文件,这是要提供给其他服务器的文件。

    【讨论】:

      【解决方案2】:

      您与该 SSH 密钥一起使用的私钥具有密码短语,但您没有在 YAML 中的任何位置指定密码短语。您可以生成供 Pipelines 专用的新密钥,也可以上传没有密码的现有密钥的副本,或者您可能能够使用环境变量来提供密码.

      【讨论】:

      • 我从 SSH 密钥下的 bitbucket 中获取了密钥公钥。我复制了该密钥并在 ~/.ssh/authorized_keys 中创建了一个新文件 authorized_keys
      • 该私钥是上传到 Pipelines 还是在那里生成的?
      • 猜猜有人用密码上传了一个,然后。您需要生成一个新的。
      猜你喜欢
      • 1970-01-01
      • 2020-01-30
      • 2021-10-23
      • 1970-01-01
      • 2022-12-19
      • 1970-01-01
      • 2019-09-09
      • 2019-03-31
      • 2018-03-19
      相关资源
      最近更新 更多