Lucas Liao's Blog

Git多账户ssh配置

为了方便学习(摸鱼),需要在公司电脑配置两个不同的github账号,分别是工作,私人的账号,在配置ssh的时候参考了网上的一些资料,实在太水,多数都是ctrl c/v搬运工,故记录下配置的过程。

一、生成ssh-key:

1
2
3
ssh-keygen -t rsa -C "work@mail.com"

ssh-keygen -t rsa -C "myself@mail.com"

二、在ssh-key目录下创建config文件

1
touch config

配置内容:

1
2
3
4
5
6
7
8
9
10
11
12
# Personal GitHub account
Host myself
HostName github.com
User Evan-Liao
IdentityFile ~/.ssh/id_rsa_myself

# Work GitHub account
Host github.com
HostName github.com
User Lucas
IdentityFile ~/.ssh/id_rsa_work

重点来了,配置文件中,根据自身需求,选择默认的Host。我目的是为了学习(摸鱼),那当然选择工作账号的ssh-key为默认的github.com,个人账号把Host改为了myself
其他平台原理一样。

三、使用

个人账号:

1
2
原指令: git clone git@github.com:Evan-Liao/blog.git
现指令: git clone git@mysel:Evan-Liao/blog.git

工作账号正常指令操作即可。