Git bash 配置ssh key

问题描述

昨天为了配置Qt create中的Git,把我一直在使用的Github删除了,今本以为,这样git的一些配置还在,可是,今天上传一些提交的时候,提示我,git没有密钥。梳理一下,这个简单的配置过程。

解决方法

  1. 检查SSH key是否存在
    $ ls -al /c/Users/lenovo/.ssh/        #*win下面的路径,在这里*
    total 37
    drwxr-xr-x 1 197121    0 8月   7 13:47 ./
    drwxr-xr-x 1 197121    0 8月   6 23:02 ../
    -rw-r--r-- 1 197121 1675 7月   3  2015 github_rsa        #旧的文件,新建以后,才知道有的(你也可以直接使用已经存在的key)
    -rw-r--r-- 1 197121  401 7月   3  2015 github_rsa.pub    #公钥,上面的是私钥
    -rw-r--r-- 1 197121 3239 8月   7 13:47 id_rsa            #新建的私钥
    -rw-r--r-- 1 197121  743 8月   7 13:47 id_rsa.pub        #新建的公钥
    -rw-r--r-- 1 197121  803 8月   7 13:54 known_hosts
    
  2. 生成SSH key 并且添加进ssh-agent里面
    $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com" # git bash 使用一个邮箱作为一个标记,生成新的ssh key
    Generating public/private rsa key pair.
    
    Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] #生成的目录,会保存在这个地方(直接回车,即可)
    
    Enter passphrase (empty for no passphrase): [Type a passphrase] #为了管理这些密钥,您也可以设置一个口令,空的话,不进行口林的设置
    Enter same passphrase again: [Type passphrase again]
    
    eval "$(ssh-agent -s)" #在git bash 中确认ssh-agent是否开启
    Agent pid 59566   #开启的话,会有个ID
    
    $ ssh-add ~/.ssh/id_rsa #添加您的私钥到ssh-agent
    
    
  3. 添加新的ssh key 到github站点
    $ clip < ~/.ssh/id_rsa.pub # 将公钥复制进剪切板,然后进入github网站的设置里面,添加公钥.*请看参考文献2*
    
  4. 测试您的ssh 链接
    ssh -T git@github.com #我本人直接是git push的,成功就ok了。不管出现什么,直接yes就可以了。
    
    Hi username! You have successfully authenticated, but GitHub does not
    provide shell access.
    
    

参考文献

  1. github ssh help
  2. github网站设置里面添加公钥

posted @ 2016-08-13 10:11  [0]  阅读(7978)  评论(0编辑  收藏  举报