安裝github
1.1 在linux上安裝github
首先可以試着在shell中輸入
git
,若提示沒有該命令,則可以使用sudo apt-get install git
來安裝,1.2 在windows上安裝github
可以在http://msysgit.github.io下載,然後默認安裝就可以了,安裝完成後有圖形用戶界面,就是下面圖中的
GitHub
,章魚貓的那個圖標。配置本地和遠程git倉庫
2.1 配置本地環境
打開 git shell ,windows用戶看起來應該是下面這個樣子
linux用戶直接在shell中輸入git
即可
接着,在shell中配置自己的信息(請忽略‘$’符號)$ git config --global user.name "Your Name" $ git config --global user.email "[email protected]"
2.2 配置遠程倉庫
我選用的github作爲遠程倉庫使用的,註冊過程不在詳細敘述。
申請好賬號之後,點擊右上角自己的頭像在彈出菜單中選擇settings
,看起來像下面這樣:
在新界面中的左側列表中選擇
SSH keys
,點擊右上角的Add SSH key
,看起來像下面這樣然後我們回到shell中,繼續生成密鑰等工作
github官網有詳細教程,鏈接地址請點這裏,github網站訪問速度慢的可以繼續看下去,去github官網看的請跳過本章2.3 生成ssh keys
首先檢測有沒有已經生成好的ssh key,windows用戶可以查看
C:\Users\username\.ssh
文件夾下有沒有github_rsa
文件,linux用戶可以在shell中輸入ls -al ~/.ssh
,若有,請跳過本步驟。
在git shell 中輸入下面第一條命令,linux用戶注意不用加sudo
ssh-keygen -t rsa -b 4096 -C "[email protected]" # Creates a new ssh key, using the provided email as a label # Generating public/private rsa key pair.
然後會提示
將密鑰文件存儲在哪
,建議使用默認位置,直接回車就好,接下來會提示是否需要密碼,不需要的話直接回車確認,需要的話輸入密碼,然後確認密碼Enter 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]
然後會提示你密鑰已經生成,像下面這個樣子
Your identification has been saved in /Users/you/.ssh/id_rsa. # Your public key has been saved in /Users/you/.ssh/id_rsa.pub. # The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
2.4 將生成的key 添加到 ssh-agent
# start the ssh-agent in the background eval "$(ssh-agent -s)" #windows用戶上面這條語句報錯的話就改成 `ssh-agent -s` # Agent pid 59566 ssh-add ~/.ssh/id_rsa
2.5 將ssh key添加到你的github賬戶中
回到我們打開的添加SSHKEY網頁,點擊
Add SSH Key
,在Title
中添加說明,用記事本之類的編輯器打開生成的id_rsa.pub
(位於.shh文件中),複製其中的內容到Key
中,然後點擊Add Key
2.6 測試連接
打開 git shell 輸入
ssh -T [email protected]
,若提示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 username! You've successfully authenticated, but GitHub does not # provide shell access.
說明連接成功,若有問題,請點擊這裏
安裝github
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.