git push origin master:权限被拒绝(公钥)错误 [英] git push origin master: permission denied (public key) error
问题描述
我已经在我的Amazon ec2 ubuntu服务器实例上设置了一个git repo.我一直在尝试将代码从本地计算机推送到服务器的存储库中.我遵循的步骤是:
I have set up a git repo on my amazon ec2 ubuntu server instance. I have been trying to push the code onto the server's repo from my local machine. The steps that I followed are:
ssh-add /path/to/myEC2publickey
在我的EC2实例上
mkdir /path/my_project.git
cd /path/my_project.git
git init --bare
后来在我的本地主机上,
Later on my localhost,
cd the_project
git init git add .
git commit -m "Initial git commit message"
git remote add origin username@hostname.com:the_project.git
git config --global remote.origin.receivepack "git receive-pack"
git push origin master
由于执行最后一条命令(即git push origin master)时出现权限定义(公钥)错误,因此我使用论坛上提供的步骤设置了公钥,该论坛包括-
Since I was getting a Permission Deined (public key) error while executing the last command (i.e. git push origin master), I set the public key using the steps given on a forum that included -
ssh-keygen -t rsa -C "myemail@somedomain.com"
eval 'ssh-agent -s'
ssh-add
我能够添加公共密钥,但是我仍然遇到权限被拒绝(公共密钥):错误.
I was able to add the public key but I am still facing the Permission Denied (public key) : Error.
我是git的新手,一直期待着将我的所有代码转换到git repo中.
I'm new to git and have been looking forward to shift all my code into a git repo.
任何帮助将不胜感激.
推荐答案
您似乎错过了(或未包含在描述中)的一个步骤是在服务器端发布公钥.
上载您的公共ssh密钥,并将其添加到~username/.ssh/authorized_keys
文件中.
One step you seem to have missed (or didn't include in your description) is the publication of the public key on the server side.
Upload your public ssh key and add it to the ~username/.ssh/authorized_keys
file.
此外,请先使用不带密码的私钥(无需ssh将您的密钥添加到ssh代理)进行尝试(用于测试)
Also, try it (for testing) first with a private key without passphrase (no need to ssh-add your key to an ssh agent)
最后,确保您的ssh密钥具有标准名称(id_rsa
和id_rsa.pub
),并具有正确的保护:
Finally, make sure your ssh keys are with standards names (id_rsa
and id_rsa.pub
), with the right protection:
- on the local side
- in the remote side
最后,如果前面的步骤不能解决问题,则ssh -Tvvv username@hostname.com
应该告诉您更多信息.
Finally, an ssh -Tvvv username@hostname.com
should tell you more, if the previous steps didn't solve the issue.
这篇关于git push origin master:权限被拒绝(公钥)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!