git-ssh 配置和使用

一、設置Git的user name和email:(若是是第一次的話)

linux$ git config --global user.name "humingx"
    $ git config --global user.email "humingx@yeah.net"

二、生成密鑰

linux$ ssh-keygen -t rsa -C "humingx@yeah.net"

連續3個回車。若是不須要密碼的話。
最後獲得了兩個文件:id_rsaid_rsa.publinux

圖片描述


若是不是第一次,就選擇overwrite.
圖片描述git

三、添加密鑰到ssh-agent

確保 ssh-agent 是可用的。ssh-agent是一種控制用來保存公鑰身份驗證所使用的私鑰的程序,其實ssh-agent就是一個密鑰管理器,運行ssh-agent之後,使用ssh-add將私鑰交給ssh-agent保管,其餘程序須要身份驗證的時候能夠將驗證申請交給ssh-agent來完成整個認證過程。github

linux# start the ssh-agent in the background
    eval "$(ssh-agent -s)"
    Agent pid 59566

添加生成的 SSH key 到 ssh-agent。shell

linux$ ssh-add ~/.ssh/id_rsa

圖片描述

四、登錄Github, 添加 ssh 。

id_rsa.pub文件裏的內容複製到這裏ssh

圖片描述


圖片描述


圖片描述


圖片描述


圖片描述

五、測試:

linux$ ssh -T git@github.com

你將會看到:ide

The authenticity of host 'github.com (207.97.227.239)' can't be established.
    RSA key fingerprint is 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測試

Hi humingx! You've successfully authenticated, but GitHub does not provide shell access.

若是看到Hi後面是你的用戶名,就說明成功了。
圖片描述fetch

六、修改.git文件夾下config中的url

修改前加密

[remote "origin"]
    url = https://github.com/humingx/humingx.github.io.git
    fetch = +refs/heads/*:refs/remotes/origin/*

修改後url

[remote "origin"]
    url = git@github.com:humingx/humingx.github.io.git
    fetch = +refs/heads/*:refs/remotes/origin/*

七、發佈

圖片描述

相關文章
相關標籤/搜索