在使用github的时候有没有遇到管理多个帐号多个项目?每个github项目都有自己的ssh密钥、那怎么处理这种情况咧?来、跟着大猪一起来操作吧。
使用教程
帐号1:abc1
帐号2:abc2
- 为帐号1生成rsa
ssh-keygen -t rsa -C "abc1"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/dounine/.ssh/id_rsa): /Users/dounine/.ssh/abc1_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/dounine/.ssh/abc1_rsa.
Your public key has been saved in /Users/dounine/.ssh/abc1_rsa.pub.
The key fingerprint is:
SHA256:1Xuzh9kmLFoFOseAc57wU/uxA8HdtZstqZHoVHDBL98 abc1
The key's randomart image is:
+---[RSA 2048]----+
| ..o. .|
| . =.. .o|
| + + B....|
| B O.*..+|
| S X OoB+.|
| o + O.XE|
| . + X +|
| o . = |
| . |
+----[SHA256]-----+
- 为帐号2生成rsa
ssh-keygen -t rsa -C "abc2"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/dounine/.ssh/id_rsa): /Users/dounine/.ssh/abc2_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/dounine/.ssh/abc2_rsa.
Your public key has been saved in /Users/dounine/.ssh/abc2_rsa.pub.
The key fingerprint is:
SHA256:1Xuzh9kmLFoFOseAc57wU/uxA8HdtZstqZHoVHDBL98 abc1
The key's randomart image is:
+---[RSA 2048]----+
| ..o. .|
| . =.. .o|
| + + B....|
| B O.*..+|
| S X OoB+.|
| o + O.XE|
| . + X +|
| o . = |
| . |
+----[SHA256]-----+
- 为两个帐号各添加ssh公钥
复制
~/.ssh/abc1_rsa.pub
与~/.ssh/abc2_rsa.pub
到对应的帐号即可。config 配置
Host abc1.com
HostName github.com
IdentityFile ~/.ssh/abc1_rsa
Host abc2.com
HostName github.com
IdentityFile ~/.ssh/abc2_rsa
- git项目配置
cat .git/config
abc1 帐号
[remote "origin"]
url = git@abc1.com:abc1/test-project
abc2 帐号
[remote "origin"]
url = git@abc2.com:abc2/test-project
提交就可以使用
git push