同一台电脑免密访问多个Github帐号方法

同一台电脑免密访问多个Github帐号方法

𝓓𝓸𝓷 Lv6
一、为不同的帐号Github创建不同的公钥

同一台电脑,不同的Github帐号,不可以使用相同的公钥访问

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
C:\Users\admin>ssh-keygen -t rsa -C 123@qq.com
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\admin/.ssh/id_rsa): C:\Users\admin/.ssh/id_rsa_hexohub
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\admin/.ssh/id_rsa_hexohub
Your public key has been saved in C:\Users\admin/.ssh/id_rsa_hexohub.pub
The key fingerprint is:
SHA256:eh90qjsF+gjHp2iu9U2k7eJ+WMJpGI0Veewx4aNuQnA 123@qq.com
The key's randomart image is:
+---[RSA 3072]----+
| .+.. |
| o.= |
| . E+ ooo |
| oo ..o. |
| .=.oS.. . |
| .o.O=o..o |
| o==O+.o |
| .o+==+o . |
| .+.o+o=o. |
+----[SHA256]-----+


C:\Users\admin>ssh-keygen -t rsa -C 456@qq.com
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\admin/.ssh/id_rsa): C:\Users\admin/.ssh/id_rsa_soxo
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\admin/.ssh/id_rsa_soxo
Your public key has been saved in C:\Users\admin/.ssh/id_rsa_soxo.pub
The key fingerprint is:
SHA256:mUOEBJAzt/Nz7g1SCqJe6KamGvpvQkX6yoVBoY46yyw 456@qq.com
The key's randomart image is:
+---[RSA 3072]----+
| o+.o... |
| .= o .. |
|.. * . . |
|o o + . o |
|...=.o S |
|..+.o.oo.. |
|=+ + o+. |
|E*= . ..o |
|&*.+. .. . |
+----[SHA256]-----+



加上-f参数一次性创建:
ssh-keygen -t rsa -C "123@qq.com" -f ~/.ssh/id_rsa_hexohub
ssh-keygen -t rsa -C "456@qq.com" -f ~/.ssh/id_rsa_soxo
会生成id_rsa_hexohub.pub和id_rsa_soxo.pub这两个文件

二、查看公钥
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
C:\Users\admin>cd .ssh

C:\Users\admin\.ssh>dir
Volume in drive C has no label.
Volume Serial Number is 70E6-2E1B

Directory of C:\Users\admin\.ssh

2024-07-03 15:48 <DIR> .
2024-07-03 05:51 <DIR> ..
2024-07-03 15:48 2,590 id_rsa_hexohub
2024-07-03 15:48 565 id_rsa_hexohub.pub
2024-07-03 15:47 2,590 id_rsa_soxo
2024-07-03 15:47 565 id_rsa_soxo.pub
2024-07-03 06:10 831 known_hosts
2024-07-03 06:10 93 known_hosts.old
8 File(s) 10,404 bytes
2 Dir(s) 1,331,605,504 bytes free


三、本地创建config配置文件
1
2
3
4
5
6
7
8
9
10
11
12
C:\Users\admin\.ssh\config   # 修改config文件,如果没有则创建config文件,添加如下内容

Host soxo.github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_soxo

Host hexohub.github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_hexohub

四、远程Github添加Key

将id_rsa_hexohub.pub和id_rsa_soxo.pub中的内容分别添加至各自的帐号中:
登录github,点击头像—设置—SSH and GPG keys—New SSH key—粘贴—Add SSH key

五、测试连接
1
2
3
4
5
C:\Users\admin>ssh -T git@soxo.github.com
Hi soxo! You've successfully authenticated, but GitHub does not provide shell access.

C:\Users\admin>ssh -T git@hexohub.github.com
Hi hexohub! You've successfully authenticated, but GitHub does not provide shell access.
六、hexo配置文件_config.yml添加deploy部署参数
1
2
3
4
5
6
7
8
9
10
deploy:

- type: git
repo: git@hexohub.github.com:hexohub/hexohub.github.io.git
branch: main

- type: git
repo: git@soxo.github.com:soxo/soxo.github.io.git
branch: gh-pages

七、上传代码
1
C:\Users\admin\hexo>hexo clean && hexo g && hexo d
  • Title: 同一台电脑免密访问多个Github帐号方法
  • Author: 𝓓𝓸𝓷
  • Created at : 2024-07-07 16:23:32
  • Updated at : 2024-07-20 05:15:41
  • Link: https://www.zhangdong.me/hexo-access-github.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论