同一臺電腦上使用gitlab和github

2021-07-14 13:32:41 字數 1617 閱讀 6190

在公司實習,使用的是公司郵箱賬號登入gitlab,而使用自己的私人郵箱賬號登入github,因此需要生成兩個ssh的key對應不同的伺服器。

使用命令

$ ssh -keygen -t rsa -c "youremailaddress"
生成key,其預設在~/.ssh/目錄下生成id_rsa和id_rsa.pub兩個檔案。

由於在公司的賬戶已經使用了這兩個預設的檔案,所以在為github配置key時,在使用上條命令產生key時可以設定將key儲存在其他地方,我使用了github_rsa和github_rsa.pub這兩個檔案。

以下是操作的關鍵!!!

然後在.ssh檔案下建立config檔案並開啟

$ touch config

$ vim config

寫入配置:

# gitlab

host gitlab

hostname git.***

user your_username

identityfile ~/.ssh/id_rsa

#github

host github

hostname github.com

user your_username

identityfile ~/.ssh/github_rsa

然而,此時如果想要從github上使用git clone的話會出現permission denied(public key)錯誤。使用命令

$ ssh -v [email protected]
最後幾行會顯示如下資訊

debug1: next authentication method: publickey

debug1: offering rsa public key: /users/***/.ssh/id_rsa

debug1: authentications that can continue: publickey

debug1: trying private key: /users/***/.ssh/id_dsa

debug1: trying private key: /users/***/.ssh/id_ecdsa

debug1: trying private key: /users/***/.ssh/id_ed25519

debug1: no more authentication methods to try.

permission denied (publickey).

個人的理解是git預設尋找id_rsa檔案作為public key,然而現在這個id_rsa已經是公司賬戶使用的key,二者郵箱不同,自然不能使用。我們的key在github_rsa中。

使用命令

$ ssh-add -l
發現金鑰列表為空,所以使用

$ ssh-add ~/.ssh/github_rsa
新增金鑰。

使用命令

$ ssh -t [email protected]
測試連線,驗證通過!

同一臺電腦同時連線gitlab 碼雲

同一臺電腦,同時連線gitlab 與 碼雲,記錄一下。這台電腦是windows 系統。之前安裝了git bash.首先,我們需要生成兩套金鑰,然後把兩套金鑰分別給gitlab 與 碼雲設定上。然後,每次在本地倉庫提交 的時候之前,設定好user.name 與 user.email。首先生成兩套金鑰 ...

在一台電腦上同時關聯GitLab和GitHub

git 客戶端與伺服器端的通訊支援多種協議,其中ssh是最常用的。ssh的公鑰登入流程 使用者將自己的公鑰儲存在遠端主機,登入時,遠端主機會向使用者傳送一條訊息,使用者用自己的私鑰加密後,再發給伺服器。遠端主機用事先儲存的公鑰進行解密,如果成功,就證明使用者可信。ssh keygen t rsa c...

同一臺電腦 多ssh配置

ps 此文基於你已經能夠正常的生成sshkey 對於sshkey的功能這裡就不多做介紹了,本文介紹的是乙個更高階的功能 同一臺電腦配置多個sshkey,方便本機在和不同的伺服器 不同的專案之間 通訊的時候自動切換賬號 以下兩種任選一種即可 1.生成新的ssh key並命名為 custom rsa s...