Deploying to ec2 instance failing when access GitH

2019-06-02 07:03发布

I set up my GitHub account about a year ago, and generated a new SSH key at the time (to easily push and pull from GitHub from Command Line). A few days ago I spun up a new ec2 instance, and downloaded the .pem file it gave me to SSH into it. I am able to easily SSH into the server through the command line using that .pem file.

I'm using Capistrano to deploy my Rails app, and running the cap staging deploy:check. In the deploy.rb file, I have the private repo git url, and in the staging.rb file I have set the set ssh_options to the location of the .pem file I downloaded from ec2 instance.

When the command starts to run, it is connecting to the server fine, but when it tries to access the git repo, GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/<APP_NAME>/git-ssh.sh /usr/bin/env git ls-remote -h git@github.com:<USERNAME>/<APP_NAME>.git, it fails with the message:

Permission denied (publickey).
fatal: Could not read from remote repository.

Been researching this issue online, and from what I've gathered it seems like I need the same SSH for both GitHub and the ec2 server. Perhaps my information is incorrect...Have been unsuccessful thus far.

Would love some advice into this issue. Thank you for your time.

1条回答
爷的心禁止访问
2楼-- · 2019-06-02 07:31

If the issue is to register a public key to your GitHub account, you can easily convert a pem to an ssh key:

openssl rsa -in MYFILE.pem -pubout > MYFILE.pub
ssh-keygen -f MYFILE.pub -i -m PKCS8

The first command is in "openSSL: how to extract public key?".
The second one in "Convert pem key to ssh-rsa format".

As the OP Justin confirms:

I just used PuttyGen to convert the .pem to the format GitHub wanted...it was prefixed with ssh-rsa.

查看更多
登录 后发表回答