為了方便隨時使用,將公司git賬號和個人git賬號配置在同一臺電腦上。
公司賬號:gitA@email.com
個人賬號:gitB@email.com
假設公司gitA@email.com 已經配置,現在添加gitB@email.com。
1、配置帳號
$ git config --global user.name "gitB"
$ git config --global user.email "gitB@email.com"
2、生成ssh密鑰
$ ssh-keygen -t rsa -C "gitB@email.com"
3、設置名稱為id_rsa_two(隨意,后面配對使用就行)
$ Enter file in which to save the key (/Users/Administrator/.ssh/id_rsa): id_rsa_two
4、新密鑰添加到SSH agent中
$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa_two
5、創建一個config文件,必須先進入ssh目錄下創建
$ cd ~/.ssh
$ vi config
在config中配置你使用的git,注意(id_rsa_two必須與前面一樣),然后退出保存。
Host yizhibo
HostName git.yizhibo.tv
IdentityFile ~/.ssh/id_rsa
Host aliyun
HostName code.aliyun.com
IdentityFile ~/.ssh/id_rsa_two
6、將id_rsa_two.pub中的內容添加到gitlab帳號下的SSH Key中,相信大家都會,git也有提示操作,這個就不多說了。
7、添加SSH Key 后進行測試是否連接成功
ssh -T git@code.aliyun.com
成功則
Welcome to Git@xxxx, yourname!
如失敗提示
Permission denied (publickey).
則執行
ssh-add ~/.ssh/id_rsa_two