配置git ssh key

1550阅读 0评论2017-06-29 u0402
分类:系统运维

1.  设置Git的user name和email:(如果是第一次的话)

点击(此处)折叠或打开

  1. $ git config --global user.name "ue90"
  2. $ git config --global user.email "ylty@163.com"
配置完成后可以通过

点击(此处)折叠或打开

  1. vim ~/.gitconfig
查看、修改配置,内容如下:

点击(此处)折叠或打开

  1. [user]
  2.         name = ue90
  3.         email = ylty@163.com
2.    生成密钥

点击(此处)折叠或打开

  1. ssh-keygen -t rsa -C "ylty@163.com"
如果不需要密码的话,连续三个回车,就可以了。在~/.ssh/目录下会生成id_rsa和id_rsa.pub两个文件。

点击(此处)折叠或打开

  1. $ ssh-keygen -t rsa -C "ylty@163.com"
  2. Generating public/private rsa key pair.
  3. Enter file in which to save the key (/c/Users/lj/.ssh/id_rsa):
  4. Created directory '/c/Users/lj/.ssh'.
  5. Enter passphrase (empty for no passphrase):
  6. Enter same passphrase again:
  7. Your identification has been saved in /c/Users/lj/.ssh/id_rsa.
  8. Your public key has been saved in /c/Users/lj/.ssh/id_rsa.pub.
  9. The key fingerprint is:
  10. SHA256:WHtPVMrdlDy6A0FeW7lIiRlmkL/m3ag007PLcrS4zEw ylty@163.com
  11. The key's randomart image is:
  12. +---[RSA 2048]----+
  13. | .+=+.+.+|
  14. | .+=.*oB |
  15. | . ..*.+ +|
  16. | o . + o . |
  17. | . S . + . |
  18. | . =.+ |
  19. | oE=o= . |
  20. | *++=o. |
  21. | *=+. |
  22. +----[SHA256]-----+

3.    添加密钥到ssh-agent
确保 ssh-agent 是可用的。ssh-agent是一种控制用来保存公钥身份验证所使用的私钥的程序,其实ssh-agent就是一个密钥管理器,运行ssh-agent以后,使用ssh-add将私钥交给ssh-agent保管,其他程序需要身份验证的时候可以将验证申请交给ssh-agent来完成整个认证过程。

点击(此处)折叠或打开

  1. #验证ssh-agent是否在运行
  2. eval "$(ssh-agent -s)"
  3. Agent pid 12356
添加生成的 SSH key 到 ssh-agent

点击(此处)折叠或打开

  1. ssh-add ~/.ssh/id_rsa

4.    登陆git添加ssh key
    登陆github官网:    
    



按照以上步骤将~/.ssh/id_rsa.pub中的公钥信息添加到github中。

5.    测试

点击(此处)折叠或打开

  1. ssh -T git@github.com
在git bash中输入以上命令,会看到

点击(此处)折叠或打开

  1. $ ssh -T git@github.com
  2. The authenticity of host 'github.com (192.30.255.113)' can't be established.
  3. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
  4. Are you sure you want to continue connecting (yes/no)? yes
  5. Warning: Permanently added 'github.com,192.30.255.113' (RSA) to the list of know n hosts.
  6. Hi ue90! You've successfully authenticated, but GitHub does not provide shell access.
完成以上5步就可以从github下载代码了。





上一篇:xshell可以ping通但是不能远程服务器,putty可以远程
下一篇:github开源项目提交代码流程详解