git@github.com: Permission denied (publickey).

来源:互联网 发布:萬能网络视频下载神器 编辑:程序博客网 时间:2024/06/08 19:45

关于git合并代码到github时报错的问题

https://help.github.com/articles/error-permission-denied-publickey/ 

官网给出有几个原因,我这里记录的最主要原因是没有生成ssh Keys

那么如何操作呢

第一步打开:git bash 不用进行你的资源库目录,在外面就行

第二步:检查你的目录下面有没有类似下面名称的文件这是是默认密钥名称。如果有说明你已经生成ssh key,就跳过后面生成的步骤

  • id_dsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub
  • id_rsa.pub
第三步:输入命令  ssh-keygen -t rsa -C "your_email@example.com" 

后面会提示你输入密码

  1. Enter passphrase (empty for no passphrase): [Type a passphrase]  
  2. # Enter same passphrase again: [Type passphrase again] 
生成成功之后会给出类似如下提示

  1. # Your identification has been saved in /Users/you/.ssh/id_rsa.  
  2. # Your public key has been saved in /Users/you/.ssh/id_rsa.pub.  
  3. # The key fingerprint is:  
  4. # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

然后再把新增的key 添加到ssh-agent 命令如下:需要说明的是is_rsa文件在你相应目录下面,你可以用记事本查看的

  1. # start the ssh-agent in the background  
  2. eval "$(ssh-agent -s)"  
  3. # Agent pid 59566  
  4. ssh-add ~/id_rsa  
第四步:把id_rsa.pub里面的文件复制到你的github账号上面在 setting-->ssh and GPG keys 里面添加一个key,其中title 随便写。

第五步:测试 ssh -T git@github.com  

如果有如下警告

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

不要急,直接输入yes回车就行

如果还提示权限没有,就查看你的目录 ssh -v git@github.com 是查看版本信息

               

说明你的目录有个 .ssh  看你的id_rsa.pub 文件在不在.ssh目录里面,如果不在直接复制过去


最后提示

  1. # Hi username! You've successfully authenticated, but GitHub does not  
  2. # provide shell access.  
说明已经链接成功,你现在就可以合并代码了

阅读全文
0 0
原创粉丝点击