window下配置SSH串連GitHub、GitHub配置ssh key(轉)

來源:互聯網
上載者:User

標籤:

轉自:http://jingyan.baidu.com/article/a65957f4e91ccf24e77f9b11.html
  • 此經驗分兩部分:

第一部分介紹:在windows下通過msysGit(Git for windows、Git Bash)配置SSH Keys串連GitHub。

第二部分介紹:在GitHub上建立倉庫,在本地建立項目,然後將本地項目通過SSH提交到GitHub倉庫中。 工具/原料

  • GitHub

  • msysGit(git for windows、Git Bash)

msysGit配置SSH訪問GitHub
  1. 1

    檢查本機是否有ssh key設定

    $ cd ~/.ssh 或cd .ssh

    如果沒有則提示: No such file or directory

    如果有則進入~/.ssh路徑下(ls查看當前路徑檔案,rm * 刪除所有檔案)

  2. 2

    1、使用Git Bash產生新的ssh key。

    $ cd ~  #保證當前路徑在”~”下

    $ ssh-keygen -t rsa -C "[email protected]"  #建議填寫自己真實有效郵箱地址

    Generating public/private rsa key pair.

    Enter file in which to save the key (/c/Users/xxxx_000/.ssh/id_rsa):   #不填直接斷行符號

    Enter passphrase (empty for no passphrase):   #輸入密碼(可以為空白)

    Enter same passphrase again:   #再次確認密碼(可以為空白)

    Your identification has been saved in /c/Users/xxxx_000/.ssh/id_rsa.   #產生的密鑰

    Your public key has been saved in /c/Users/xxxx_000/.ssh/id_rsa.pub.  #產生的公開金鑰

    The key fingerprint is:

    e3:51:33:xx:xx:xx:xx:xxx:61:28:83:e2:81 [email protected]

    *本機已完成ssh key設定,其存放路徑為:c:/Users/xxxx_000/.ssh/下。

    注釋:可產生ssh key自訂名稱的密鑰,預設id_rsa。

    $ ssh-keygen -t rsa -C "郵箱地址" -f ~/.ssh/githug_blog_keys #產生ssh key的名稱為githug_blog_keys,慎用容易出現其它異常。

  3. 3

    添加ssh key到GItHub

    3.1 登入GitHub系統;點擊右上方帳號頭像的“▼”→Settings→SSH kyes→Add SSH key。

  4. 4

    3.2 複製id_rsa.pub的公開金鑰內容。 

    1) 進入c:/Users/xxxx_000/.ssh/目錄下,開啟id_rsa.pub檔案,全選複製公開金鑰內容。

    2) Title自訂,將公開金鑰粘貼到GitHub中Add an SSH key的key輸入框,最後“Add Key”。

  5. 5

    配置賬戶

    $ git config --global user.name “your_username”  #設定使用者名稱

    $ git config --global user.email “your_registered_github_Email”  #設定郵箱地址(建議用註冊giuhub的郵箱)

  6. 6

    測試ssh keys是否設定成功。

    $ ssh -T [email protected]

    The authenticity of host ‘github.com (192.30.252.129)‘ can‘t be established.

    RSA key fingerprint is 16:27:xx:xx:xx:xx:xx: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.129‘ (RSA) to the list of known hosts.

    Enter passphrase for key ‘/c/Users/xxxx_000/.ssh/id_rsa‘:  #產生ssh kye是密碼為空白則無此項,若設定有密碼則有此項且,輸入產生ssh key時設定的密碼即可。

    Hi xxx! You‘ve successfully authenticated, but GitHub does not provide shell access. #出現詞句話,說明設定成功。

    END

將本地項目通過SSH push到GitHub
  1. 在github上建立一個樣本倉庫,如:test ssh key。

  2. 複製test ssh key的ssh路徑。

  3. 本地建立項目 

    1) 建立目錄

    $ mkdir test

    $ cd test

    2) 初始化

    $ git init

    3) 建立hello.md檔案

    $ echo "這是一次測試test ssh key" > hello.md

    4) 提交到本地

    若出現如上warning提示則重新提交一次即可。

    $ git add .   #提交目前的目錄下所以檔案

    $ git commit -m "add hello.md"   #提交記錄說明 

    5) 提交到github

    $ git remote add origin ‘粘貼複製test ssh key的ssh路徑’  #

    $ git push -u origin master

    Enter passphrase for key ‘/c/Users/hgpin_000/.ssh/id_rsa‘:  #ssh key設定密碼故此需要輸入密碼

  4. 重新整理test ssh key倉庫,查看hello.md。(完)

    步驟閱讀

    END

注意事項
  • 經驗適用於win7、win8.1、win10。

window下配置SSH串連GitHub、GitHub配置ssh key(轉)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.