多个git 配置ssh key

Front End

安装

brew install git
# or
# apt-get install git

## 配置ssh-key

git config --global user.name ''
git config --global user.email ''

ssh-keygen -t res -C 'email'
# 然后就是自定义
# 要不要密码随便你
# 反正下面都会进行ssh-add

上github或者gitlab, 进入setting,找到ssh-key, 点击new SSH Key 把id_rsa.pub内容粘贴进去就ok了

image

检查

ssh git@github.com

image

配置hosts

cd ~/.ssh
vim config

Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github

Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa_gitlab


# 注入密码,下次不需要再输密码(除非重启)
ssh-add -k ~/.ssh/id_rsa_gitlab

简单快捷完成git配置了