git的安裝見https://www.cnblogs.com/liliyang/p/9829931.html
配置git使用ssh密鑰
git支持https和git兩種傳輸協議,github分享鏈接時會有兩種協議可選:
若git使用https協議,每次pull, push均提示要輸入密碼,使用git協議,然后使用ssh密鑰對認證,即可實現免密
一、生成密鑰對
[root@kube-node1 ~]# 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 root@kube-node1 The key's randomart image is: +---[RSA 2048]----+ | ...+ | | o.. * | | .B.= . | | o +..Bo. | | S =o*. | | ..*o= . | | ...o=.. | | .o+=+o. | | +E*BBo | +----[SHA256]-----+ [root@kube-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
[root@kube-node1 ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnjHeR/2hDtjMZKHND2kceUPSibuemNh0J/upA0DE/fmI8Ub52ZhJ1uY7STVntseR0HrJmed96KroD4uILE40ChKOwGZjptkFIWfZ+qCDYWpCqlUus2goiNlAj7WIYnlgzif/RSqn8wZNqqozi8JqU+g1gdWZCENU9C0ONeEwP83q1mATx26k8HGSN0Gg1V2zdKLUqEhEzQ/7FHEObDyZGT7NqAFfefgTLHr6lZslsHfqM7RdRBdf5zneSPSX264SgHIWFbgZKMyMVB+Um4jtdoQf2NpHAxIUfof1Ncn34KyPJ3PN2NEvkXhdKsSLohKiESe1hkYtDy+YagdqtwLf7 root@kube-node1
要將這里的公鑰復制添加到github公鑰配置中
二、添加公鑰到自己的遠程倉庫(github)
Title隨便填寫
公鑰復制到上述的Key中,點擊Add SSH key
在本地主機上測試:
[root@kube-node1 ~]# ssh -T git@github.com 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)? yes Warning: 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
下面是在game-of-life項目的目錄中執行
[root@kube-node1 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。
[root@kube-node1 game-of-life]# git remote set-url origin git@github.com:useyunwei/game-of-life.git
[root@kube-node1 game-of-life]# git remote -v
origin git@github.com:useyunwei/game-of-life.git (fetch)
origin git@github.com:useyunwei/game-of-life.git (push)
再次使用命令 git remote -v 查看一下,url是否已經變成了ssh地址。
然后就可以愉快的使用git fetch, git pull , git push,不用再輸入密碼