根据账号生成对应的ssh key
ssh-keygen -t rsa -f ~/.ssh/id_rsa_1 -C "account1@qq.com"
ssh-keygen -t rsa -f ~/.ssh/id_rsa_2 -C "account2@qq.com"
编辑 ~/.ssh/config 文件
Host github1 // 代号而已 可随便取
user account1@qq.com
HostName github.com
IdentityFile ~/.ssh/id_rsa_1
Host github2
user account2@qq.com
HostName github.com
IdentityFile ~/.ssh/id_rsa_2
将上面创建的专用密钥添加到 ssh-agent 的高速缓存中
ssh-add ~/.ssh/id_rsa_1
ssh-add ~/.ssh/id_rsa_2
将地址的地址改成config里的host,再执行 git clone
账号1
git clone git@github.com:xxx1/xxx1.git 改成 git clone git@github1:xxx1/xxx1.git
账号2
git clone git@github.com:xxx2/xxx2.git 改成 git clone git@github2:xxx2/xxx2.git
如果无法克隆,可先通过https方式克隆下来,再修改 .git/config 里的url地址为ssh地址即可
本地已存在的项目可通过修改项目下 .git/config 文件里的url地址
拓展:
1. 查看当前登录账号:
git config user.name
2. 查看当前登录邮箱:
git config user.email
3. 修改当前项目下用户名和邮箱:
git config user.name "Your_username"
git config user.email "Your_email"
4. 全局修改用户名和邮箱:
git config --global user.name "Your_username"
git config --global user.email "Your_email"