git-ssh 配置和使用


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

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

 

2、生成密鑰

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

 

連續3個回車。如果不需要密碼的話。
最后得到了兩個文件:id_rsaid_rsa.pub


如果不是第一次,就選擇overwrite.

3、添加密鑰到ssh-agent

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

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

 

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

$ ssh-add ~/.ssh/id_rsa

 

4、登陸Github, 添加 ssh 。

id_rsa.pub文件里的內容復制到這里





5、測試:

$ ssh -T git@github.com

 

你將會看到:

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后面是你的用戶名,就說明成功了。

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

修改前

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

 

修改后

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

 

7、發布

 

原文:

https://segmentfault.com/a/1190000002645623


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM