zWingz / my-blog-config

my-blog-config
MIT License
2 stars 0 forks source link

多个git 配置ssh key #7

Open zWingz opened 6 years ago

zWingz commented 6 years ago

安装

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配置了