Git bash 配置ssh key


問題描述

昨天為了配置Qt create中的Git,把我一直在使用的Github刪除了,今本以為,這樣git的一些配置還在,可是,今天上傳一些提交的時候,提示我,git沒有密鑰。梳理一下,這個簡單的配置過程。

解決方法

  1. 檢查SSH key是否存在
    $ ls -al /c/Users/lenovo/.ssh/        #*win下面的路徑,在這里*
    total 37
    drwxr-xr-x 1 197121    0 8月   7 13:47 ./
    drwxr-xr-x 1 197121    0 8月   6 23:02 ../
    -rw-r--r-- 1 197121 1675 7月   3  2015 github_rsa        #舊的文件,新建以后,才知道有的(你也可以直接使用已經存在的key)
    -rw-r--r-- 1 197121  401 7月   3  2015 github_rsa.pub    #公鑰,上面的是私鑰
    -rw-r--r-- 1 197121 3239 8月   7 13:47 id_rsa            #新建的私鑰
    -rw-r--r-- 1 197121  743 8月   7 13:47 id_rsa.pub        #新建的公鑰
    -rw-r--r-- 1 197121  803 8月   7 13:54 known_hosts
    
  2. 生成SSH key 並且添加進ssh-agent里面
    $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com" # git bash 使用一個郵箱作為一個標記,生成新的ssh key
    Generating public/private rsa key pair.
    
    Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] #生成的目錄,會保存在這個地方(直接回車,即可)
    
    Enter passphrase (empty for no passphrase): [Type a passphrase] #為了管理這些密鑰,您也可以設置一個口令,空的話,不進行口林的設置
    Enter same passphrase again: [Type passphrase again]
    
    eval "$(ssh-agent -s)" #在git bash 中確認ssh-agent是否開啟
    Agent pid 59566   #開啟的話,會有個ID
    
    $ ssh-add ~/.ssh/id_rsa #添加您的私鑰到ssh-agent
    
    
  3. 添加新的ssh key 到github站點
    $ clip < ~/.ssh/id_rsa.pub # 將公鑰復制進剪切板,然后進入github網站的設置里面,添加公鑰.*請看參考文獻2*
    
  4. 測試您的ssh 鏈接
    ssh -T git@github.com #我本人直接是git push的,成功就ok了。不管出現什么,直接yes就可以了。
    
    Hi username! You have successfully authenticated, but GitHub does not
    provide shell access.
    
    

參考文獻

  1. github ssh help
  2. github網站設置里面添加公鑰


免責聲明!

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



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