標籤:
原文連結 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管理