項目又一次從svn切換到git,並且要求使用安全協議ssh鏈接git。無論是我的仍是組織,git上只負責導入公鑰,而不會幫你生成。這裏先說下怎麼生成這個ssh的私鑰和公鑰。linux
首先你得找到有ssh命令的環境,無論是windows仍是unix的。假設我已經安裝了遠程鏈接到linux環境的客戶端了,那麼我直接登陸linux環境,敲入命令生成鑰匙git
[personal@ZJHZ-CMREAD-TEST126 ~]$ ssh-keygen -t rsa -C "youremail@139.com" -b 4096 Generating public/private rsa key pair. Enter file in which to save the key (/home/personal/.ssh/id_rsa): Created directory '/home/personal/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/personal/.ssh/id_rsa. Your public key has been saved in /home/personal/.ssh/id_rsa.pub. The key fingerprint is: c8:97:d1:65:55:32:1a:a2:f2:6d:bf:c3:8e:df:8d:3a youremail@139.com The key's randomart image is: +--[ RSA 4096]----+ | . +.+..| | o + o o | | . o . . | | . + + | | o S o | | . . . | | .. | | .Eo o | | .o=+o .| +-----------------+
上面這裏沒有設置密語和密碼,一路回車下來,這樣就生成了。有了鑰匙就要拿來用了。先在本地C盤你的用戶目錄下新建一個.ssh目錄(好比個人是C:\Users\wulf\.ssh),而後到linux環境上取鑰匙。由於.ssh是隱藏目錄,咱們能夠先cd進去,把私鑰id_rsa和公鑰id_rsa.pub兩個文件cp出來,再經過ftp下載到本地的.ssh目錄下。windows
最後一步是到git配置公鑰,先打開id_rsa.pub,Ctrl + C。登錄git -> 點開頭像 -> 點進setting ->接下來兵分兩路: 若是是我的,點SSH and GPG keys -> 點 New SSH key,到key下面的框裏Ctrl + V,最後點Add SSH key;若是是組織,點SSH keys -> 到key下面的框裏Ctrl + V,最後點Add key。git會先校驗一下,而後同步成功。這時你就能夠直接經過ssh鏈接本地git倉庫和遠程倉庫了。安全
這裏以eclipse鏈接爲例,咱們先在git上找個項目,點一下Clone按鈕,再到eclipse裏點開File -> Import -> Git -> Projects from Git -> Clone URI -> Next -> 直接輸入密碼便可,啥都不用幹,完事。dom