通过 SSH 访问 codeship 上的 github repo

SSH access to github repo on codeship

我正在尝试从 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

有什么我遗漏的吗?

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

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

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