mac 一臺電腦兩個github賬號
自己有兩個github賬號,要配置在同一臺筆記本上
個人賬號:itxingOne@163.com
公司賬號:itxingTwo@163.com
假設個人賬號已經配置,現在添加公司賬號itxingTwo@163.com
1.配置賬號
$ git config --global user.name "itxingTwo"
$ git config --global user.email "itxingTwo@163.com"
2.生成ssh密鑰
$ ssh-keygen -t rsa -C "itxingTwo@163.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
$ touch config
6.在config中配置你使用的git
Host github.com
? HostName github.com
? IdentityFile ~/.ssh/id_rsa
Host github_two
? HostName github.com
? IdentityFile ~/.ssh/id_rsa_two
7.將id_rsa_two.pub中的內容添加到gitlab帳號下的SSH Key中
8.添加SSH Key后進行測試是否連接成功
$ ssh -T github.com
成功則
Welcome to Git@xxxx, yourname!
失敗則
Permission denied (publickey).
解決方案
$ ssh-add ~/.ssh/id_rsa_two