一台電腦上的git同時使用兩個github賬戶

2022-09-16 01:42:11 字數 2468 閱讀 7932

需求:

公司有github賬號,自己有github賬號,想在git上同時使用,兩者互不干擾。

思路:

管理兩個shh key。

解決方案:

一、生成兩個ssh key

為了舉例方便,這裡使用「one」和「two」兩個賬戶。下同。

$ ssh-keygen -t rsa -c "

[email protected]"$

ssh-keygen -t rsa -c "

[email protected]

"

不要一路回車,分別在第乙個對話的時候輸入重新命名(id_rsa_oneid_rsa_two),這樣會生成

兩份包含私鑰和公鑰的4個檔案。

注1:ssh-keygen是linux命令,可以讓兩個機器之間使用ssh而不需要使用者名稱和密碼

住2:一定要在~/.ssh路徑下執行命令列,不然生成的檔案不會出現在當前目錄

二、新增私鑰

1、開啟ssh-agent

(1)如果你是github官方的bash:

$ ssh-agent -s
(2) 如果你是其它,比如msysgit:

$ eval $(ssh-agent -s)
2、新增私鑰

$ ssh-add ~/.ssh/id_rsa_one

$ ssh-add ~/.ssh/id_rsa_two

三、建立config檔案

$ touch config
此時會出現空的config檔案,然後新增如下內容:

# one([email protected])

host one.github.com

hostname github.com

preferredauthentications publickey

identityfile ~/.ssh/id_rsa_one

user one

# two(two@ gmail.com)

host two.github.com

hostname github.com

preferredauthentications publickey

identityfile ~/.ssh/id_rsa_two

user two

四、部署ssh key分別登陸兩個github賬號,進入personal settings–>ssh and gpg keys

點選"new ssh key", 把下面兩個公鑰的內容分別新增到相應的github賬號中。

五、遠端測試【可跳過】

$ ssh

–t one.github.com

$ ssh –t two.github.com

六、使用1、clone到本地

(1)原來的寫法:

$ git clone [email protected]: one的使用者名稱/learngit.git
(2)現在的寫法:

$ git clone [email protected]: one的使用者名稱/learngit.git

$ git clone [email protected]: two的使用者名稱/learngit.git

$ git config user.name "

one_name

" ; git config user.email "

one_email

"$ git config user.name

"two_name

" ; git config user.email "

two_email

"

3、上述都成功後,會發現鑰匙會由灰變綠。

一台電腦分兩個電腦使用

需要兩套鍵鼠和顯示器,我用的是筆記本,所以插筆記本上,需要你的usb介面夠用!預設安裝就可以了,這個軟體並不是虛擬機器然後我的顯示器只是個擴充套件模式,一台電腦兩個螢幕而已!進入軟體 在通常設定裡,可以看到是12個終端,也就是說只要你電腦性能夠,可以同時可以12個人使用,我們點選終端2 選擇允許,然...

一台電腦上使用兩個GitHub賬戶

使用ssh keygen生成兩個ssh key,目錄內容如下 ll ssh total 15 rw r r 1 cui 197121 336 九月 15 10 25 config rw r r 1 cui 197121 1675 七月 19 22 56 id rsa rw r r 1 cui 197...

一台電腦上的git同時使用多個github賬戶

需求 公司有gitlib賬號,某個開源專案有github賬號,自己有github賬號,自己也有gitee賬號,想在git上同時使用,這麼多賬號如何做到 兩者互不干擾。思路 管理n個shh key,這裡就拿兩個舉個例子吧 解決方案 一 生成兩個ssh key 為了舉例方便,這裡使用 one 和 two...