Git SSH Key 生成步驟
Git是分布式的代碼管理工具,遠程的代碼管理是基於SSH的,所以要使用遠程的Git則需要SSH的配置。
github的SSH配置如下:
一 、
設置Git的user name和email:
$ git config --global user.name "xuhaiyan"
$ git config --global user.email "[email protected]"
二、生成SSH密鑰過程:
1.查看是否已經有了ssh密鑰:cd ~/.ssh
如果沒有密鑰則不會有此文件夾,有則備份刪除
2.生存密鑰:
$ ssh-keygen -t rsa -C “[email protected]”
按3個回車,密碼為空。([email protected]是github的賬號,即上面的email)
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.添加id_rsa密鑰到ssh,命令為:ssh-add 文件名
如果出現error:Could not open a connection to your authentication agent.
則先執行:$ssh-agent bash
然後再執行:$ssh-add id_rsa
4.在github上添加ssh密鑰,這要添加的是“id_rsa.pub”裏面的公鑰。
打開https://github.com/ ,登陸,復制id_rsa.pub裏面的內容添加ssh。
如果直接從Linux上復制id_rsa.pub的內容,可能會復制裏面的換行符,而key是沒有換行符的,直接復制可能會出現下面的錯誤提示:
Key is invalid
Fingerprint has already been taken
Fingerprint cannot be generated
解決方案:
$cat id_rsa.pub
然後復制裏面的內容,就OK了!
5.測試:ssh [email protected] 連接成功!
PTY allocation request failed on channel 0
Welcome to GitLab, ***!
Connection to github.com closed.
三、 開始使用github
1.獲取源碼(在本地創建一個目錄,進入目錄git clone):
$ git clone [email protected]: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”
Git SSH Key 生成步驟