在GitHub多個帳號上添加SSH公開金鑰

來源:互聯網
上載者:User

標籤:

GitHub後台可以添加多個SSH Keys,但是同一個SSH Keys只能在添加在一個帳號上(添加時提示“Key is already in use”)。理由很容易想到,SSH公開金鑰使用時相當於使用者名稱密碼,不可能兩個不同的帳號使用同一個使用者名稱密碼。要想在多個GitHub帳號上添加公開金鑰,就要在本地產生多個SSH Keys,每個GitHub帳號對應一個不同的SSH Keys。步驟如下:
1、產生一個新的SSH KEY

  1. [email protected]:~$ ssh-keygen -t rsa -C ‘[email protected]‘
  2. Generating public/private rsa key pair.
  3. Enter file in which to save the key (~/.ssh/id_rsa): ~/.ssh/id_rsa2 #這裡輸入一個新的ssh key檔案名稱
  4. Enter passphrase (empty for no passphrase):
  5. Enter same passphrase again:
  6. Your identification has been saved in ~/.ssh/id_rsa2.
  7. Your public key has been saved in ~/.ssh/id_rsa2.pub.
  8. The key fingerprint is:
  9. 3a:01:17:b3:f9:26:5b:53:b3:69:be:71:a8:66:f6:96 [email protected].me
  10. The key‘s randomart image is:
  11. +--[ RSA 2048]----+
  12. | o |
  13. | = |
  14. | . + o |
  15. | . . . + |
  16. | o S + |
  17. | B + . |
  18. | + .+ + |
  19. | .E..+ |
  20. | +.oo |
  21. +-----------------+
  22. [email protected]:~$ ssh-add ~/.ssh/id_rsa2
  23. Identity added: ~/.ssh/id_rsa2 (~/.ssh/id_rsa2)

~/.ssh/id_rsa2為新SSH Keys檔案名稱,根據實際情況修改,保證每次不一樣即可。
2、開啟新產生的~/.ssh/id_rsa2.pub檔案,將裡面的內容添加到GitHub後台。
3、開啟~/.ssh/config檔案(沒有則建立),添加一個Host:

  1. #建一個github別名,建立的帳號使用這個別名做複製和更新
  2. Host github2
  3. HostName github.com
  4. User git
  5. IdentityFile ~/.ssh/id_rsa2.pub

4、將GitHub SSH倉庫地址中的[email protected]替換成建立的Host別名。
如原地址是:[email protected]:freehost/mail.git,替換後應該是:github2:freehost/mail.git
如果是建立的倉庫,直接使用替換後的URL複製即可。如果已經使用原地址複製過了,可以使用命令修改:

  1. git remote set-url origin github2:freehost/mail.git

原創文章,轉載請註明: 轉載自www.webmaster.me

本文連結地址: 在GitHub多個帳號上添加SSH公開金鑰

在GitHub多個帳號上添加SSH公開金鑰

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.