【问题标题】:SSH access to github repo on codeship通过 SSH 访问 codeship 上的 github repo
【发布时间】:2019-05-22 12:48:14
【问题描述】:

我正在尝试从 Codeship 上的容器推送到 github。在收到Permission denied (publickey) 错误后,我按照这里的建议:

https://documentation.codeship.com/pro/builds-and-configuration/setting-ssh-private-key/

我创建了一个名为publish 的服务,并通过一些步骤尝试重新创建文章的建议。

我的 codeship_services.yml 文件:

# codeship_services.yml
publish:
  build: 
    image: codeship/setting-ssh-key-test
    dockerfile: Dockerfile.publish
  encrypted_env_file: codeship.env.encrypted
  volumes:
    - ./.ssh:/root/.ssh

我的 codeship_steps.yml 文件:

- name: temp publish service
  service: publish
  command: /bin/bash -c "echo -e $PRIVATE_SSH_KEY >> /root/.ssh/id_rsa"

- name: chmod id_rsa
  service: publish
  command: chmod 600 /root/.ssh/id_rsa

- name: add server to list of known hosts
  service: publish
  command: /bin/bash -c "ssh-keyscan -H github.com >> /root/.ssh/known_hosts"

- name: confirm ssh connection to server, authenticating with generated public ssh key
  service: publish
  command: /bin/bash -c "ssh -T git@github.com"

但是,在运行 jet steps 时,我仍然收到 Permission denied (publickey) 错误:

(step: temp_publish_service) success ✔
(step: chmod_id_rsa) 
(step: chmod_id_rsa) success ✔
(step: add_server_to_list_of_known_hosts) 
(service: publish) (step: add_server_to_list_of_known_hosts) # github.com:22 SSH-2.0-babeld-80573d3e
(service: publish) (step: add_server_to_list_of_known_hosts) # github.com:22 SSH-2.0-babeld-80573d3e
(service: publish) (step: add_server_to_list_of_known_hosts) # github.com:22 SSH-2.0-babeld-80573d3e
(step: add_server_to_list_of_known_hosts) success ✔
(step: confirm_ssh_connection_to_server,_authenticating_with_generated_public_ssh_key) 
(service: publish) (step: confirm_ssh_connection_to_server,_authenticating_with_generated_public_ssh_key) Permission denied (publickey).
(step: confirm_ssh_connection_to_server,_authenticating_with_generated_public_ssh_key) error ✗
(step: confirm_ssh_connection_to_server,_authenticating_with_generated_public_ssh_key) container exited with a 255 code

我已经按照文章中的说明生成了密钥,并将加密后的私钥添加到codeship.env.encryped

我有什么遗漏吗?

【问题讨论】:

    标签: bash git docker ssh codeship


    【解决方案1】:

    唯一缺少的步骤是注册public Key on your GitHub account itself

    只有这样,使用相同公钥的 SSH 连接才有机会成功。

    如果没有,请在最后一步中至少尝试ssh -Tvv git@github.com,以获得更多线索。

    【讨论】:

    • 谢谢@VonC!如果此 repo 是组织的一部分,则密钥是否位于“部署密钥”下?我在组织的 repo 上没有看到 ssh 密钥的位置。
    • @Tyler stackoverflow.com/a/21395835/6309:只要您的 GitHub 帐户是组织的一部分,您自己的帐户就足够了。
    猜你喜欢
    • 2014-02-19
    • 2021-12-20
    • 2021-08-27
    • 1970-01-01
    • 1970-01-01
    • 2011-10-08
    • 2022-01-17
    • 2017-03-01
    • 2021-11-17
    相关资源
    最近更新 更多