windows環境下 生成公鑰和私鑰
- 上傳代碼到遠程倉庫的時候需要秘鑰進行驗證是否本人上傳的。打開Git目錄下的Git Bash
輸入ssh-keygen,回車
- 可直接不輸入路徑,使用默認路徑(c/Users/Administrator/.ssh/)
- 按照提示要輸入兩次密碼,但是如果輸入了,每次操作操作git庫時都要輸入密碼,所以選擇不輸入密碼
- 密碼輸入結束后,提示已生成秘鑰
- 打開c:/Users/Administrator/.ssh/,在文件中,id_rsa是私鑰文件,id_rsa.pub是公鑰文件
- 將公鑰文件內容添加到github中的ssh公鑰
- 回到git bash,輸入
ssh -T git@git.oschina.net
- 如果顯示 'Welcome to Git@OSC, your username!',則表示成功
修改本地的ssh remote url。不用https協議,改用git協議
- 查看當前的remote url,可以看到是使用https協議進行訪問的
git remote -v
orgin https://github.com/xxx/xxx.git(fetch)
orgin https://github.com/xxx/xxx.git(push)
- 調整url,使用項目的ssh url
git remote set-url origin git@github.com:xxx/xxx.git