Windows管理gitee和GitHub SSH秘钥
本文记录基于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出现这种情况是正常的
本文来自博客园,作者:勤匠,转载请注明原文链接:https://www.cnblogs.com/JarryShu/p/17082883.html