无法将项目从本地推送到AWS中设置的git存储库:权限被拒绝(公钥)



我是AWS的新手,按照教程在AWS中设置git并将我的本地文件推入其中。我随身携带一个扩展名为.pem的Key,它是在创建实例时生成的。我添加了远程存储库,如下所示:git remote add production ssh://root@35.154.37.131/var/repo/site.git

在这之后,当我试图推入存储库时,我得到了:

$ git push production master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

我在谷歌上搜索了一下,但无法找到解决方案。但是,我可以使用以下方法ssh到我的实例:

ssh -i wexpert_instance_2.pem ubuntu@ec2-35-154-37-131.ap-south-1.compute.amazonaws.com

请帮忙。

我尝试过进行git远程添加生产ssh://ubuntu@ec2-35-154-37-131.ap-south-compute.amazonaws.com/var/report/site.git

这是意料之中的事,因为SSH默认情况下会在~/.ssh/id_rsa中查找您的密钥。

由于您没有默认密钥,因此需要定义一个~/.ssh/config文件(chmod 644(,其中包含:

Host myaws
Hostname ec2-35-154-37-131.ap-south-1.compute.amazonaws.com
User ubuntu
IdentityFile /full/path/to/wexpert_instance_2.pem

然后:

git remote set-url production myaws:/var/repo/site.git

最新更新