配置github SSH公開金鑰登入

來源:互聯網
上載者:User

標籤:https協議   ssh   int   ocs   pass   pre   drbd   項目目錄   permanent   

git的安裝見https://www.cnblogs.com/liliyang/p/9829931.html

配置git使用ssh密鑰

git支援https和git兩種傳輸協議,github分享連結時會有兩種協議可選:

 

 

 若git使用https協議,每次pull, push均提示要輸入密碼,使用git協議,然後使用ssh金鑰組認證,即可實現免密

  配置git 通過ssh協議免密需要三個步驟: 1、產生金鑰組 2、配置遠程倉庫(這裡使用github)上的公開金鑰 3、把git的 remote url 修改為git協議(以上兩個步驟初次設定過以後,以後使用都不需要再次設定, 此步驟視以後項目的remote url而定,如果以後其他項目的協議為https則需要此步驟) 一、產生金鑰組
[[email protected] ~]# ssh-keygen  Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:SHA256:fO7pVFqZ464nC8H6B3pTE8cwPx2mTM0G8KJt7Or2L8o [email protected]-node1The key‘s randomart image is:+---[RSA 2048]----+|          ...+   ||          o.. *  ||          .B.= . ||       o +..Bo.  ||        S =o*.   ||       ..*o= .   ||      ...o=..    ||      .o+=+o.    ||       +E*BBo    |+----[SHA256]-----+[[email protected]-node1 ~]# ll .ssh/total 8-rw------- 1 root root 1679 Oct 23 11:32 id_rsa-rw-r--r-- 1 root root  397 Oct 23 11:32 id_rsa.pub

[[email protected] ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnjHeR/2hDtjMZKHND2kceUPSibuemNh0J/upA0DE/fmI8Ub52ZhJ1uY7STVntseR0HrJmed96KroD4uILE40ChKOwGZjptkFIWfZ+qCDYWpCqlUus2goiNlAj7WIYnlgzif/RSqn8wZNqqozi8JqU+g1gdWZCENU9C0ONeEwP83q1mATx26k8HGSN0Gg1V2zdKLUqEhEzQ/7FHEObDyZGT7NqAFfefgTLHr6lZslsHfqM7RdRBdf5zneSPSX264SgHIWFbgZKMyMVB+Um4jtdoQf2NpHAxIUfof1Ncn34KyPJ3PN2NEvkXhdKsSLohKiESe1hkYtDy+YagdqtwLf7 [email protected]

要將這裡的公開金鑰複製添加到github公開金鑰配置中

 

二、添加公開金鑰到自己的遠程倉庫(github)

Title隨便填寫

 公開金鑰複製到上述的Key中,點擊Add SSH key

 

在本地主機上測試:

[[email protected]-node1 ~]# ssh -T [email protected]The authenticity of host ‘github.com (192.30.253.113)‘ can‘t be established.RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added ‘github.com,192.30.253.113‘ (RSA) to the list of known hosts.Hi useyunwei! You‘ve successfully authenticated, but GitHub does not provide shell access.

 

 

三、修改git的remote url

 使用命令 git remote -v (需在事先clone的項目目錄中執行)查看你當前的 remote url

 下面是在libgit2項目的目錄中執行

[[email protected] game-of-life]# git remote -v
origin https://github.com/useyunwei/game-of-life.git (fetch)
origin https://github.com/useyunwei/game-of-life.git (push)

如果是以上的結果那麼說明此項目是使用https協議進行訪問的(如果地址是git開頭則表示是git協議)

可以登陸你的github,在上面可以看到你的ssh協議相應的url,類似:

 

複製上述的ssh連結,然後使用命令 git remote set-url 來調整url。

[[email protected] game-of-life]# git remote set-url origin [email protected]b.com:useyunwei/game-of-life.git
[[email protected] game-of-life]# git remote -v
origin [email protected]:useyunwei/game-of-life.git (fetch)
origin [email protected]:useyunwei/game-of-life.git (push)

再次使用命令 git remote -v 查看一下,url是否已經變成了ssh地址。

然後就可以愉快的使用git fetch, git pull , git push,不用再輸入密碼

  

 

配置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.