IlyaSemenov / gitlab-ci-git-push

Gitlab CI runner image that pushes to a remote Git repo (Dokku, Heroku, Deis, etc.)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Permission denied (publickey) error when pushing to GitHub

emreiyican-zz opened this issue · comments

I tried to set up the Gitlab CI as described but I'm getting this error:

Warning: Permanently added the RSA host key for IP address '140.82.114.3' to the list of known hosts. Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

This tells me everything is ok but the SSH keys.

One thing is ticking me is what is directed in this repos README (GitLab > Project > Settings > CI/CD > Secret Variables) and what is available at Gitlab right now is different. I'm suspicious that something has changed at Gitlab that broke this.

The Gitlab repo is https://gitlab.com/emreiyican/newsletter-server
The GitHub repo is https://github.com/emreiyican/newsletter_server

The .gitlab-ci.yml is below

`
image: ilyasemenov/gitlab-ci-git-push

variables:
GIT_DEPTH: 1000

stages:

  • push

before_script:

  • 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
  • eval $(ssh-agent -s)
  • mkdir -p ~/.ssh
  • chmod 700 ~/.ssh
  • echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -

push to github:
stage: push
environment: production
script: git-push emreiyican@github.com:newsletter_server
`

I also tried without the 'before_script' part and got the same result.

I created the keys with ssh-keygen -f temp.key -q -N "" && cat temp.key && cat temp.key.pub on my machine. Pasted both outputs to their respective places as printed.

At Gitlab, the SSH_PRIVATE_KEY is configured as a Variable, with environment scope production and protect variable selected.

To debug I added a line to echo the SSH_PRIVATE_KEY in the Gitlab CI file and saw that it was successfully printing the private key.

After working on this for 2 days, and writing this issue, I decided to check closed issues. It appears I made the same mistake of #13

Changed the git-push command to script: git-push git@github.com:emreiyican/newsletter_server

I'm closing the issue.