通过SSH访问github代码仓库

时间:2019-05-22 02:31:00

标签: bash git docker ssh 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中。

有什么我想念的吗?

1 个答案:

答案 0 :(得分:1)

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

只有使用相同公共密钥的SSH连接才有机会成功。

否则,请在最后一步中至少尝试使用ssh -Tvv git@github.com,以获得更多线索。