同一台電腦使用多個sshkey

來源:互聯網
上載者:User

標籤:

參考連結:http://higrid.net/c-art-github_share_ssh.htm

http://yijiebuyi.com/blog/f18d38eb7cfee860c117d629fdb16faf.html

 

1、使用命令建立個ssh-key

tingdeMacBook-Pro:ContinuousIntegration ting$ ssh-keygen -t rsa -C ‘[email protected]‘

2、注意命令運行時輸入新的檔案名稱:

tingdeMacBook-Pro:ContinuousIntegration ting$ ssh-keygen -t rsa -C ‘[email protected]‘Generating public/private rsa key pair.Enter file in which to save the key (/Users/ting/.ssh/id_rsa): /Users/ting/.ssh/id_rsa_xxxx163_githubEnter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /Users/ting/.ssh/id_rsa_xxxx163_github.Your public key has been saved in /Users/ting/.ssh/id_rsa_xxxx163_github.pub.The key fingerprint is:……

3、預設SSH只會讀取id_rsa,所以為了讓SSH識別新的私密金鑰,需要將其添加到SSH agent

ssh-add ~/.ssh/id_rsa_xxxx163_githubIdentity added: /Users/ting/.ssh/id_rsa_xxxx163_github (/Users/ting/.ssh/id_rsa_xxxx163_github)

4、完成以上步驟後在~/.ssh目錄建立config檔案,該檔案用於配置私密金鑰對應的伺服器。內容如下:

# Default github user([email protected])Host github.comHostName github.com User git IdentityFile C:/Users/username/.ssh/id_rsa# second user([email protected])Host github-second HostName github.com User git IdentityFile C:/Users/username/.ssh/id_rsa_second

5、Host隨意即可,方便自己記憶,後續在添加remote是還需要用到。 配置完成後,在串連非預設帳號的github倉庫時,遠程庫的地址要對應地做一些修改,比如現在添加second帳號下的一個倉庫test,則需要這樣添加:

git remote add test [email protected]:second/test.git #並非原來的[email protected]:second/test.git

注意: github根據設定檔的user.email來擷取github帳號顯示author資訊,所以對於多帳號使用者一定要記得將user.email改為相應的email([email protected])。

 

同一台電腦使用多個sshkey

聯繫我們

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