查看: 5|回复: 0

Windows管理gitee和GitHub SSH秘钥

[复制链接]

1

主题

0

回帖

0

积分

热心网友

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2011-12-12
发表于 2023-2-1 15:06:00 | 显示全部楼层 |阅读模式

本文记录基于Windows账户对Gitee和GitHub两个平台的SSH管理,Mac用户暂时没有试过;如果没有GitHub和Gitee账号,先去注册!

首先

git全局配置,配置了就不用管这步了

$ git config --global user.name "你的用户名"
$ git config --global user.email "你的邮箱"

第1步:生成秘钥

CMD进入 C://Users//用户名/.ssh目录下(如果没有这个目录,新建一个.ssh文件夹)

1.1 生成Gitee SSH秘钥

请注意第1和第3行

C:\Users\Jarry\.ssh> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\Jarry/.ssh/id_rsa): gitee
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in gitee.
Your public key has been saved in gitee.pub.
The key fingerprint is:
SHA256:g8XZjKDYa1yliSu2MYzMxQxzChUw2zuBJlhwhn9PahY jarry@LAPTOP-RUJ5JGBJ
The key's randomart image is:
+---[RSA 3072]----+
|=B*o  . .        |
|+OKo o * =       |
|=++++ + = o      |
|=oo+E+.o         |
|.oO.==. S        |
| . B+ .  .       |
|  .o             |
|                 |
|                 |
+----[SHA256]-----+

1.2 生成GitHub SSH秘钥

请注意第1和第3行

C:\Users\Jarry\.ssh> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\Jarry/.ssh/id_rsa): github
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in github.
Your public key has been saved in github.pub.
The key fingerprint is:
SHA256:g8XZjKDYa1yliSu2MYzMxQxzChUw2zuBJlhwhn9PahY jarry@LAPTOP-RUJ5JGBJ
The key's randomart image is:
+---[RSA 3072]----+
|=M*o  . .        |
|+OSo o * =       |
|=++++ + = o      |
|=oo+E+.o         |
|.oO.==. S        |
| . B+ .  .       |
|  .o             |
|                 |
|                 |
+----[SHA256]-----+

第2步: 配置config

上述2步做完后,.ssh目录下应该有4份文件,分别是

  • gitee
  • gitee.pub
  • github
  • github.pub

如果有known_hosts和known_hosts.old不用管。有上述4份文件就对了~,在.ssh文件夹下新建一个config文件,录入以下信息👇,保存并退出

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github

第3步:Gitee和GitHub配置秘钥

配置Gitee秘钥

打开.ssh文件夹下的gitee.pub文件,拷贝里面的所有内容;然后打开gitee平台,进入设置,按如下方法操作

配置GitHub秘钥

打开.ssh文件夹下的github.pub文件,拷贝里面的所有内容;然后打开github平台,进入设置,按如下方法操作

第4步:测试一下好使不?

CMD中输入

C:\Users\xxx\.ssh>ssh -t git@gitee.com
Warning: Permanently added the ED25519 host key for IP address '212.64.63.215' to the list of known hosts.
Hi xxxxx! You've successfully authenticated, but GITEE.COM does not provide shell access.
Connection to gitee.com closed.
C:\Users\xxx\.ssh>ssh -t git@github.com
Warning: Permanently added the ECDSA host key for IP address '20.205.243.166' to the list of known hosts.
PTY allocation request failed on channel 0
# github毕竟是国外的服务器,国内不FQ出现这种情况是正常的
回复

使用道具 举报

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

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部