【git搭建】建立本地倉庫與github(遠程倉庫)的傳輸

本地Git倉庫和github倉庫之間的傳輸是經過SSH加密傳輸的git

1. 生成密鑰

ssh-keygen -t rsa -b 4096 -C "youremail@example.com"

宿主目錄 /用戶/username/.ssh/目錄下,會生產 id_rsa.pub(公鑰) 和id_rsa(密鑰) 兩個文件github

2. ssh代理: ssh-agent

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

# eval `ssh-agent -s` :啓動代理,直接啓動一個 ssh-agent 進程
eval `ssh-agent -s`  #這裏是反引號
ssh-add –l

3. 在遠程倉庫李配置公鑰

登陸github,打開」settings」中的SSH Keys頁面,而後點擊「Add SSH Key」,填上任意title,在Key文本框裏黏貼id_rsa.pub文件的內容。ssh

4. 進行同步的時候可能遇到的問題

  • 問題1.fatal: HTTP request failed , 403 Forbidden!

如: error: The requested URL returned error: 403 Forbidden while accessing測試

能夠看見多是權限問題致使fetch

解決方法:加密

能夠修改.git/config文件追加用戶名和密碼:
1)編輯.git/config文件
2)在[remote 「origin」]下找到找到url變量
3)修改url = https://github.com/user/test.git,修改成url = ssh://git@github.com/user/test.git,修改完了保存
  • 問題2: 測試鏈接遠程倉庫報錯

輸入命令:進行測試url

ssh git@github.com

可能報錯:代理

The authenticity of host 'github.com (192.30.252.131)' 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    #這裏寫 yes
Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts.
Permission denied (publickey).

說是主機密鑰驗證失敗, 發現是缺乏了 known_hosts 文件, 並且必須生成 github.com 的ip執行內容.code

  • 問題3: push到github時,每次都要輸入用戶名和密碼的問題

緣由:可能使用的https 方法,而非 shell方式

解決方式:查看遠程倉庫信息

git remote -v

origin https://github.com/yuquan0821/demo.git (fetch)
origin https://github.com/yuquan0821/demo.git (push)

把https換成shell方式

git remote rm origin 
git remote add origin git@github.com:yuquan0821/demo.git
git push origin
``

- 問題4: 推送時報郵箱錯誤

錯誤信息:remote: error: GH007: Your push would publish a private email address.

解決方法:在GitHub的你帳號網頁上右上角,我的的登陸退出的位置,找到setting:    setting->emails->Keep my email address private,把這一項去掉勾選便可。
相關文章
相關標籤/搜索