Bootstrap

Git同时配置Github和Gitee

一、生成对应的公私钥文件

注意在以下过程中,不要输入密码,直接回车即可,否则在之后的操作都需要输入密码,如果不小心输入密码,重新输入下面的命令,进行覆盖即可。

ssh-keygen -t rsa -C '你的邮箱' -f ~/.ssh/id_rsa_github
ssh-keygen -t rsa -C '你的邮箱' -f ~/.ssh/id_rsa_gitee

生成后,在 .ssh 文件夹下会出现各自的公私钥。
公私钥

二、将公钥添加到Github和Gitee上

GitHub -> Settings -> SSH and GPG keys -> SSH keys -> New SSH key

将 id_rsa_github.pub 文件内容复制到下面的 Key 中。
添加公钥

Gitee -> 设置 -> 安全设置 -> SSH公钥

将 id_rsa_gitee.pub 文件内容复制到下面的公钥中。
在这里插入图片描述

三、添加配置文件

在 .ssh 文件夹中创建 config 文件,输入如下内容。

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

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

config

四、测试是否配置成功

ssh -T git@gitee.com
ssh -T git@github.com

若出现如下情况,输入 fingerprint ,接着输入 yes 。
fingerprint
成功。
成功

;