有时候我们可能需要在同一台电脑上针对不同平台同时使用多个Git账户的情况,这时候我们就需要针对多个平台和账户进行不同的设置。
同时管理多个SSH key。
~/.ssh
目录下进行,否则生成的SSH key不会在~/.ssh
目录下,所以以下有操作都是在~/.ssh
目录下进行的。在生成之前尽量删除此目录下的所有文件再进行,以免出现不必要的问题。ssh-keygen -t rsa -C "one@email.com"
ssh-keygen -t rsa -C "two@email.com"
Enter file in which to save the key
的时候对ssh文件进行重命名(idrsaone和idrsatwo
),这样就会生成如下目录中的四个文件。
即两份包含私钥和公钥的4个文件。
cat ~/.ssh/id_rsa_one.pub
cat ~/.ssh/id_rsa_two.pub
其中idrsaone.pub和idrsatwo.pub
就是上面对ssh文件重命名的文件名。
有了这个密钥,你就可以将其添加到你所需要用的平台上去。
touch config
这样就会在~/.ssh
目录下生成一个空的config
文件,然后我们在文件中添加以下内容:
# git server one
Host one.aliyun.com #别名
Hostname code.aliyun.com #真实域名
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_one #ssh 文件路径
User one
#git server two
Host two.aliyun.com
Hostname code.aliyun.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_two
User two
ssh –T one.aliyun.com
ssh –T two.aliyun.com
git clone git@code.aliyun.com:项目路径.git
git clone git@one.github.com:项目路径.git
git clone git@two.github.com:项目路径.git
git config user.name "one_name"; git config user.email "one_email"
git config user.name "two_name"; git config user.email "two_email"
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有