Windows下生成GitHub/Gitee SSH key

打印 上一主题 下一主题

主题 623|帖子 623|积分 1869

前提:已安装git。
1、输入以下命令生成ssh key,一路回车即可。(xxxx@xxx.com为你注册GitHub的邮箱)(注意,Gitee只需这一步,然后复制密码就好)
GitHub:ssh-keygen -t rsa -C "xxxx@xxx.com"
Gitee:ssh-keygen -t ed25519 -C "xxxx@xxx.com"
  1. $ ssh-keygen -t rsa -C  "xxxx@xxx.com"
  2. Generating public/private rsa key pair.
  3. Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
  4. Enter passphrase (empty for no passphrase):
  5. Enter same passphrase again:
  6. Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa
  7. Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub
  8. The key fingerprint is:
  9. SHA256:/ydX+AEdhH+HOukbM2knJNHjaa+vPhctxE70hDJv4ys  "xxxx@xxx.com"
  10. The key's randomart image is:
  11. +---[RSA 3072]----+
  12. |              oo |
  13. |           .o.o..|
  14. |          . o*o+.|
  15. |           o +Oo+|
  16. |        S . =O.+o|
  17. |         . ++o*.o|
  18. |          ..B.o*.|
  19. |           oEB= .|
  20. |           .*@.  |
  21. +----[SHA256]-----+
复制代码
2、输入命令:eval "ssh-agent -s"
  1. $ eval "ssh-agent -s"
  2. SSH_AUTH_SOCK=/tmp/ssh-pdrfl8Q4DvbK/agent.585; export SSH_AUTH_SOCK;
  3. SSH_AGENT_PID=586; export SSH_AGENT_PID;
  4. echo Agent pid 586;
复制代码
3、继续输入命令:ssh-add ~/.ssh/id_rsa
  1. $ ssh-add ~/.ssh/id_rsa
  2. Identity added: /c/Users/Administrator/.ssh/id_rsa (xxxx@xxx.com)
复制代码
如果报错(Could not open a connection to your authentication agent.),则需要先执行命令:ssh-agent bash,再执行上述命令
 
4、复制生成的key到GitHub
查看key:cat ~/.ssh/id_rsa.pub(Gitee:$ cat .ssh/id_ed25519.pub)
  1. $ cat ~/.ssh/id_rsa.pub
  2. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCbLVIplXKxgdi2fi2ZhPW6o5dtF/mSeE3CmlFxmfUDoDgPaQDqebEiOaBNBN1GYvcpQxLXTkRuA9g7nf8DnH3qKfUq98QftsxbAcwvH1Xr0EcJFakMx7d0pGFH1RQ/kVr1iU3kKU4wuKhQn73Momje18BormKovP5InObSWNu7TAtkhmgF43W31NJjqS+mJ9v62Y7r65uetUgRwv9+MGJP3CO62TTLjdIom8VpK5uch7EGm3x6FYt8VT3urZS/ji/ixlvKaRJ7X1MJrCbQQ+8EfHejpKhQxZ0HU3p8CIjdbL1d9j1wIc8kz11zrEaoNSPdwK9J8pnl2o+TjoNQIUvNd0JHDsosCZARB0tzmuS0WnA3VvoldcIsMBfGC52bKW/zWuKkSUS0j+BTDvyk3aaS//ITmCnwffQeBo8C3A59KY00bEGDAWjhWhxJvQAhw3Qum7bZTIrC/glhwSxOcFSSEh0gu9hLLLQ2iq5CiNfbNv8/JpTPIDp/G+irUQ7URrE= "xxxx@xxx.com"
复制代码
GitHub位置如下:

 
 
 
5、检查是否成功:
ssh -T "git@github.com" (Gitee:ssh -T git@gitee.com)
  1. GitHub的连不上,Gitee倒是连上了
复制代码
$ ssh -T git@gitee.com
The authenticity of host 'gitee.com (212.64.63.215)' can't be established.
ED25519 key fingerprint is SHA256:+ULzij2u99B9eWYFTw1Q4ErYG/aepHLbu96PAUCoV88.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitee.com' (ED25519) to the list of known hosts.
Hi mikasama! You've successfully authenticated, but GITEE.COM does not provide shell access.
 
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

万万哇

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表