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 [email protected]
- 如果顯示 'Welcome to Git@OSC, your username!',則表示成功
修改本地的ssh remote url。不用https協定,改用git協定
-
git remote -v orgin https://github.com/xxx/xxx.git(fetch) orgin https://github.com/xxx/xxx.git(push)
-
git remote set-url origin [email protected]:xxx/xxx.git