git clone 权限被拒绝

想要使用git向自己的github上传代码,得先把github上的仓库克隆下来,但是出现了下面的接收失败错误!!!


解决办法如下:(参考http://my.oschina.net/chape/blog/119983)

1 前提:已安装ssh

2 检查SSH公钥

cd ~/.ssh

看看存不存在.ssh,如果存在的话,直接跳过到下一步;不存在的话请看下一步,按照操作进行

3 生成SSH公钥
$ ssh-keygen -t rsa -C " your_email @youremail.com" 
# Creates a new ssh key using the provided email Generating public/private rsa key pair. 
Enter file in which to save the key (/home/you/.ssh/id_rsa):

直接按回车,现在你可以看到,在自己的目录下,有一个.ssh目录,说明成功了!!!

3.1 在接下来提示输入密码的时候输入你的github密码

Enter passphrase (empty for no passphrase): [Type your github passphrase] 
Enter same passphrase again: [Type your github passphrase again]

这个时候输入你在github上设置的密码。

3.2 然后在.ssh中可以看到

Your identification has been saved in /home/you/.ssh/id_rsa. 
# Your public key has been saved in /home/you/.ssh/id_rsa.pub.
# The key fingerprint is: 
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:dbyour_email@youremail.com

4 添加SSH公钥到github

打开github,找到账户里面添加SSH,把id_rsa.pub用记事本或者notpad++打开,将内容复制到key里面。

5 测试是否生效

使用下面的命令测试

ssh -T [email protected]

当你看到这些内容放入时候,直接输入yes

The authenticity of host 'github.com (207.97.227.239)' can't be established. 
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. 
Are you sure you want to continue connecting (yes/no)?

看到这个内容放入时候,说明就成功了。

Hi username! 
You've successfully authenticated, but GitHub does not provide shell access.

当你想要把自己的代码上传到github上时,需先在自己的github上创建一个仓库,然后使用Git GUI(必须是Git GUI 不能是Git bash,bash不支持上传!)。把你要上传到的仓库的url拷贝到下面的Source Location的text框里,再在Target Directory的text框里输入你要克隆到的文件目录(必须是未创建的,否则会报错),然后点击“克隆”,会提示输入你的github账号及密码,正确后即可克隆到指定的目录里。


再把你要上传的代码文件都复制到该目录里,然后在出现的下一个对话框里按照顺序依次点击就能成功上传了。上传成功会有提示信息,并且能在你的github主页上看到你的上传内容。

猜你喜欢

转载自blog.csdn.net/qq_534019165/article/details/50857245
今日推荐