Git SSH Key 生成

假裝我是程式猿發表於2017-11-12

Git是分散式的程式碼管理工具,遠端的程式碼管理是基於SSH的,所以要使用遠端的Git則需要SSH的配置。
github的SSH配置如下:

一、設定Git的user name和email:
$ git config --global user.name "DevonChina"

$ git config --global user.email "admin@fanxiao2.net"複製程式碼
二、生成SSH金鑰過程:
1.檢視是否已經有了ssh金鑰:cd ~/.ssh

如果沒有金鑰則不會有此資料夾,有則備份刪除

2.生存金鑰:
$ ssh-keygen -t rsa -C "admin@fanxiao2.net"複製程式碼

按3個回車,密碼為空。

Your identification has been saved in /home/tekkub/.ssh/id_rsa.
Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
The key fingerprint is:
………………複製程式碼

最後得到了兩個檔案:id_rsa和id_rsa.pub

3.新增金鑰到ssh:ssh-add 檔名

需要之前輸入密碼。

4.在github上新增ssh金鑰,這要新增的是“id_rsa.pub”裡面的公鑰。

開啟github.com/ ,登陸DevonChina,然後新增ssh。

5.測試:ssh 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
Warning: Permanently added ‘github.com,207.97.227.239′ (RSA) to the list of known hosts.
ERROR: Hi tekkub! You’ve successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.複製程式碼
三、 開始使用github
1.獲取原始碼:
$ git clone git@github.com:billyanyteen/github-services.git複製程式碼
2.這樣你的機器上就有一個repo了。
3.git於svn所不同的是git是分散式的,沒有伺服器概念。所有的人的機器上都有一個repo,每次提交都是給自己機器的repo

倉庫初始化:

git init複製程式碼

生成快照並存入專案索引:

git add複製程式碼

檔案,還有git rm,git mv等等…
專案索引提交:

git commit複製程式碼
4.協作程式設計:

將本地repo於遠端的origin的repo合併,
推送本地更新到遠端:

git push origin master複製程式碼

更新遠端更新到本地:

git pull origin master複製程式碼

補充:
新增遠端repo:

$ git remote add upstream git://github.com/pjhyett/github-services.git複製程式碼

重新命名遠端repo:

$ git://github.com/pjhyett/github-services.git為“upstream”複製程式碼

覺得我分享的文章對你有幫助或者對內容有什麼異議,請聯絡微信公眾號:範小二

相關文章