【轉】同一台電腦關於多個SSH KEY管理

來源:互聯網
上載者:User

標籤:

 

原文連結 http://yijiebuyi.com/blog/f18d38eb7cfee860c117d629fdb16faf.html

 

使用環境:關於同一台電腦LInux系統下使用多個SSH key 切換使用(或者多使用者使用ssh提交代碼)

要求,可以建立不同的 PUBLIC KEY ,根據下面步驟設定.

(1)比如有aaa,bbb,ccc 三個帳號需要產生不同的 PUBLIC KEY

$ ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa):/root/.ssh/id_rsa_aaaEnter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /root/.ssh/id_rsa_aaa.Your public key has been saved in /root/.ssh/id_rsa_aaa.pub.The key fingerprint is:9b:92:f6:1f:d2:72:bd:72:19:45:42:5f:e4:65:33:64 [email protected]The key‘s randomart image is:+--[ RSA 2048]----+|           .. .E=||            ..o++||             o. .||              .  ||        S    .   ||       . + ..    ||      + = + .o   ||     . o +..o.   ||        ...o.    |+-----------------+

 進過上面的shell 我們在 /root/.ssh/ 目錄下建立 id_rsa_aaa  私密金鑰 和 id_rsa_aaa.pub 公開金鑰

注意這裡

Enter file in which to save the key (/root/.ssh/id_rsa):/root/.ssh/id_rsa_aaa  #設定路徑,如果不設定預設產生 id_rsa  和  id_rsa.pub

(2)按照上面的步驟逐個產生 bbb 和 ccc 對應的公開金鑰和私密金鑰 ........

(3)查看系統ssh-key代理,執行如下命令

$ ssh-add -lCould not open a connection to your authentication agent.如果發現上面的提示,說明系統代理程式裡沒有任何key,執行如下操作exec ssh-agent bash

如果系統已經有ssh-key 代理 ,執行下面的命令可以刪除

$ ssh-add -D

 

(4)把 .ssh 目錄下的3個私密金鑰添加的 ssh-agent

$ ssh-add ~/.ssh/id_rsa_aaa$ ssh-add ~/.ssh/id_rsa_bbb$ ssh-add ~/.ssh/id_rsa_ccc

依次執行上面三條shell 把三個私密金鑰添加到 ssh-key 代理裡面

(5)開啟github 或者 開源中國 ssh 管理頁面把 對應的公開金鑰提交儲存到代碼管理伺服器 (.pub 結尾)

(6)在 .ssh 目錄建立 config 設定檔

nano ~/.ssh/config

輸入如下配置資訊

#aaa  (github 配置)Host aaa    HostName github.com    User git    IdentityFile ~/.ssh/id_rsa_aaa#bbb  (開源中國 配置)Host bbb    HostName git.oschina.net    User git    IdentityFile ~/.ssh/id_rsa_bbb#ccc........

(6)記住上面一步 Host 裡設定的別名,開始複製項目,以開源中國為例

git clone [email protected]:userName/projectName.git

到此為止多個ssh-key 已經可以同時使用.

【轉】同一台電腦關於多個SSH KEY管理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.