Git中如何利用生成SSH我的公鑰訪問git倉庫方法(這裏以coding平臺爲例):git
在項目的代碼頁面點擊 SSH 切換到 SSH 協議, 得到訪問地址, 請使用這個地址來訪問您的代碼倉庫,以下圖:ssh
Mac/Linux 打開命令行終端, Windows 打開 Git Bash 。 輸入ssh-keygen -t rsa -C 「username@example.com」,( 註冊的郵箱),接下來點擊enter鍵便可(也能夠輸入密碼)。ide
$ssh-keygen -t rsa -b 4096 -C "your_email@example.com" // 按回車enter # 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]
// 推薦使用默認地址,若是使用非默認地址可能須要配置 .ssh/config ,在前面標下劃的對應目錄下能夠看到生成的公鑰文件
成功以後測試
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 your_email@example.com
本地打開 id_rsa.pub 文件(或執行 $cat id_rsa.pub ),複製其中所有內容,添加到帳戶「SSH 公鑰」頁面 中,公鑰名稱能夠隨意起名字。spa
$ ssh -T git@git.coding.net // 按回車enter
.net
Enter passphrase for key ‘/c/Users/Yuankai/.ssh/id_rsa’: Coding.net Tips : [ Hello Kyle_lyk! You have connected to Coding.net by SSH successfully! ] `命令行
注意: 同一個公鑰只能綁定一個帳戶,Coding 暫時不支持同一公鑰綁定多個帳戶。code
若是須要使用多個帳戶建議生成多個公鑰,能夠在.ssh/config文件中加上下邊一段regexp
Host git.coding.net User xxxx@email.com PreferredAuthentications publickey IdentityFile ~/.ssh/coding_rsa // 生成的非默認地址的公鑰存放點
1.在本地目錄鼠標右鍵選擇 GIT GUI HERE打開GUI窗口選擇克隆已經存在的倉庫以下圖:blog
2.輸入git倉庫SSH地址上面已經說過
OK,祝您成功,有上面問題能夠留言一塊兒討論!