標籤: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公開金鑰登入