[TOC] #### 1. 問題描述 --- 使用 git clone 拉取 github 倉庫時報錯 ``` $ git clone git@github.com:shinyboys/test.git Cloning into 'test'... git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. ``` ``` Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hos ``` 當使用 git push 將本地代碼推送到遠程倉庫時也會報錯  #### 2. 生成 SSH 公鑰 --- 這個應該是很多 github 新手會遇到的問題,原因就是當前電腦沒有權限操作 github 倉庫。解決辦法: 當前電腦生成 ssh 密鑰文件,將 ssh 公鑰添加到 github 賬號上,然后就可以正常拉取、推送代碼了 執行生成 ssh 密鑰的命令, 會有交互性操作,提示讓輸入密碼, 直接一路回車即可 ssh-keygen 用于生成、管理、轉換認證秘鑰 參數: -t,type 指定要創建的秘鑰類型,可取值: rsa1(SSH-1)、rsa(SSH-2)、dsa(SSH-2) ``` ssh-keygen -t rsa ``` 查看生成的 SSH 公鑰 ``` cat ~/.ssh/id_rsa.pub ```  mac 系統生成 ssh 公鑰  #### 3. 在 github 上添加 SSH 公鑰 --- **前往個人中心設置 `Settings`**  **點擊左側欄目 `SSH and GPG keys`**  **將生成的 SSH 公鑰保存到 github 中, 建議標題標明 SSH 公鑰來源**  #### 4. 在 gitee 上添加 SSH 公鑰 ---  #### 5. 重新拉取項目 --- ``` git clone git@github.com:shinyboys/test.git ``` 