当前位置:   article > 正文

如何在Github上配置ssh key的密钥_github密钥添加格式

github密钥添加格式

Step0 : 解释说明

git使用SSH配置, 初始需要以下三个步骤

  1. 使用秘钥生成工具生成rsa秘钥和公钥
  2. 将rsa公钥添加到代码托管平台
  3. 将rsa秘钥添加到ssh-agent中,为ssh client指定使用的秘钥文件

Step 1: 核验本地主机是否已经存在ssh密钥。(若id_rsa和id_rsa.pub文件存在,说明已经存在SSH key密钥,反之,需要生成新密钥)

  1. Maxwell Pan@MaxwellPan MINGW64 ~
  2. $ cd ~/.ssh
  3. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  4. $ ls
  5. known_hosts
  6. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh

Step 2:生成ssh key

如果不存在ssh key,使用如下命令生成

  1. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  2. $ ssh-keygen -t rsa -C "xxxxxxxx@xxx.com"
  3. Generating public/private rsa key pair.
  4. Enter file in which to save the key (/c/Users/Maxwell Pan/.ssh/id_rsa):
  5. Enter passphrase (empty for no passphrase):
  6. Enter same passphrase again:
  7. Your identification has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa
  8. Your public key has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa.pub
  9. The key fingerprint is:
  10. SHA256:QqppfBW5oA8VAGjWSTouObN23WwhnVowrLbPGLreok4 xxxxxxx@xxx.com
  11. The key's randomart image is:
  12. +---[RSA 3072]----+
  13. |o.+oo |
  14. |.o.o.. . |
  15. |oo o++ |
  16. |...o.++o. |
  17. |=.oo..+=S |
  18. |.=.=o.*.. |
  19. |.E=+oo + |
  20. |oo+.= . |
  21. |==oo o |
  22. +----[SHA256]-----+
  23. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  24. $ ls
  25. id_rsa id_rsa.pub known_hosts
  26. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh

 

生成完以后再用第二步命令,查看ssh key

Step3:获取ssh key公钥内容(id_rsa.pub)

  1. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  2. $ ls
  3. id_rsa id_rsa.pub known_hosts
  4. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  5. $ cat id_rsa.pub
  6. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDFWXsAPl4sGCgRjTSVOZlxfv2ZWYBteE0gYdmN6A8teeUkh6WCsbqyVtUUNkaaUC9Zpn0xUb8hpMr9Cbhiyy90D2mIuxK37RQWi4mz5PSGIXZ/tNQ/n8oFNrhmAx7ljWmFxvmMB4CVIUCujpYunj6P8vBZaIrR5+Rakec8gjxxxxxxxxxxxxxxxxxGllKPpuVa9f4KjRet0BRXg4oiXE8DB6bODsAjSnBrYlf3Cj3EyhQyA07qygQLEzUItDRMNfLT5UpYTjBk/RqFbB9KpGTtkH9B++lLC6nosN1dwLugEdW05P+SGfay3xlFmc7+f/lgP3xxxxxxxxxxxxxxxxxxxxx80u9mA2RNDz1gqji1sL6K0IdbmqJ7vOi/xBfPs3kswVZxoDiWr8Bh4/xYRYm53rORPLWvMN+AQlCLVq9GlYb2y2mN37PU5qUjs3INzPE9TV1F4EhMl2E5DQhHcbMmILwyqe9+8= xxxxxxxxx@xxxx.com
  7. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh

复制cat 的内容到Github账号上去 设置密钥。首先点击头像下的setting , 找到SSH and GPG keys这个栏位。点击 New SSH key,将上面cat出来的内容添加到New SSH key,并取个名字。

 Step 4 : 验证 配置密钥是否成功。

  1. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  2. $ ssh -T git@github.com
  3. Hi psmaxwell! You've successfully authenticated, but GitHub does not provide shell access.
  4. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  5. $

设置成功后,即可不需要账号密码clone和push代码

以下为全过程:

  1. Maxwell Pan@MaxwellPan MINGW64 ~
  2. $ cd ~/.ssh
  3. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  4. $ ls
  5. known_hosts
  6. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  7. $ ssh-keygen -t rsa -C "xxxxxxxx@qq.com"
  8. Generating public/private rsa key pair.
  9. Enter file in which to save the key (/c/Users/Maxwell Pan/.ssh/id_rsa):
  10. Enter passphrase (empty for no passphrase):
  11. Enter same passphrase again:
  12. Your identification has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa
  13. Your public key has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa.pub
  14. The key fingerprint is:
  15. SHA256:QqppfBW5oA8VAGjWSTouObN23WwhnVowrLbPGLreok4 xxxxxxxxxx@qq.com
  16. The key's randomart image is:
  17. +---[RSA 3072]----+
  18. |o.+oo |
  19. |.o.o.. . |
  20. |oo o++ |
  21. |...o.++o. |
  22. |=.oo..+=S |
  23. |.=.=o.*.. |
  24. |.E=+oo + |
  25. |oo+.= . |
  26. |==oo o |
  27. +----[SHA256]-----+
  28. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  29. $ ls
  30. id_rsa id_rsa.pub known_hosts
  31. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  32. $ cat id_rsa.pub
  33. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDFWXsAPl4sGCgRjTSVOZlxfv2ZWYBteE0gYdmN6A8teeUkh6WCsbqyVtUUNkaaUC9Zpn0xUb8hpMr9Cbhiyy90D2mIuxK37RQWi4mz5PSGIXZ/tNQ/n8oFNrhmAx7ljWmFxvmMB4CVIUCujpYunj6P8vBZaIrR5+Rakec8gjvxxxxxxxxxxxxaw6YoE1qrGllKPpuVa9f4KjRet0BRXg4oiXE8DB6bODsAjSnBrYlf3Cj3EyhQyA0xxxxxxxxxk/RqFbB9KpGTtkH9B++lLC6nosN1dwLxxxxxxxxxFmc7+f/lgP3bTb9egBjTpYqRC48fwOtYqbmP2HN0wX+9T0c4+9X80u9mA2RNDz1gqji1sL6K0IdbmqJ7vOi/xBfPs3kswVZxoDiWr8Bh4/xYRYm53rORPLWvMN+AQlCLVq9GlYb2y2mN37PU5qUjs3INzPE9TV1F4EhMl2E5DQhHcbMmILwyqe9+8= xxxxxxxxxxx@qq.com
  34. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  35. $ ssh -T git@github.com
  36. Hi psmaxwell! You've successfully authenticated, but GitHub does not provide shell access.
  37. Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
  38. $

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号