git push origin master:权限被拒绝(公钥)错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21179896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git push origin master: permission denied (public key) error
提问by Amit Nandan Periyapatna
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:
我已经在我的 amazon ec2 ubuntu 服务器实例上设置了一个 git repo。我一直在尝试将代码从本地机器推送到服务器的存储库中。我遵循的步骤是:
ssh-add /path/to/myEC2publickey
On my EC2 Instance
在我的 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 [email protected]:the_project.git
git config --global remote.origin.receivepack "git receive-pack"
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 -
由于我在执行最后一个命令(即 git push origin master)时遇到权限定义(公钥)错误,我使用论坛上给出的步骤设置了公钥,其中包括 -
ssh-keygen -t rsa -C "[email protected]"
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.
我能够添加公钥,但我仍然面临权限被拒绝(公钥):错误。
I'm new to git and have been looking forward to shift all my code into a git repo.
我是 git 的新手,一直期待将我的所有代码转移到 git 存储库中。
Any help would be greatly appreciated.
任何帮助将不胜感激。
采纳答案by VonC
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 密钥并将其添加到~username/.ssh/authorized_keys
文件中。
Also, try it (for testing) first with a private key without passphrase (no need to ssh-add your key to an ssh agent)
此外,首先使用没有密码短语的私钥尝试(用于测试)(无需将您的密钥 ssh 添加到 ssh 代理)
Finally, make sure your ssh keys are with standards names (id_rsa
and id_rsa.pub
), with the right protection:
最后,确保您的 ssh 密钥具有标准名称(id_rsa
和id_rsa.pub
),并具有正确的保护:
- on the local side
- in the remote side
Finally, an ssh -Tvvv [email protected]
should tell you more, if the previous steps didn't solve the issue.
最后,ssh -Tvvv [email protected]
如果前面的步骤没有解决问题,应该告诉你更多。
回答by Amit Nandan Periyapatna
The complete procedure being:
完整的程序是:
Add the EC2 public key to your ssh list with the following command
ssh-add /path/to/myEC2publickey
Create a git repository on the EC2 instance with the following commands
mkdir /path/my_project.git cd /path/my_project.git git init --bare
Connect the local files on your system to your repository with the commands
cd the_project git init git add . git commit -m "Initial git commit message" git remote add origin [email protected]:the_project.git git config --global remote.origin.receivepack "git receive-pack" git push origin master
Create a public key as the user and add it to the server's authorized keys
You can do this step by just copying the file id_rsa.pub from the localhost to the servers ~/.ssh/authorized_keys file, as suggested in the previous answer.
使用以下命令将 EC2 公钥添加到您的 ssh 列表
ssh-add /path/to/myEC2publickey
使用以下命令在 EC2 实例上创建一个 git 存储库
mkdir /path/my_project.git cd /path/my_project.git git init --bare
使用命令将系统上的本地文件连接到存储库
cd the_project git init git add . git commit -m "Initial git commit message" git remote add origin [email protected]:the_project.git git config --global remote.origin.receivepack "git receive-pack" git push origin master
以用户身份创建公钥并将其添加到服务器的授权密钥中
您可以通过将文件 id_rsa.pub 从本地主机复制到服务器的 ~/.ssh/authorized_keys 文件来完成此步骤,如上一个答案中所述。
After following these steps if you try the git push, you should not get a "permission denied" error.
如果您尝试使用 git push 执行这些步骤后,您应该不会收到“权限被拒绝”错误。