[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 ``` 當(dāng)使用 git push 將本地代碼推送到遠(yuǎn)程倉庫時也會報錯  #### 2. 生成 SSH 公鑰 --- 這個應(yīng)該是很多 github 新手會遇到的問題,原因就是當(dāng)前電腦沒有權(quán)限操作 github 倉庫。解決辦法: 當(dāng)前電腦生成 ssh 密鑰文件,將 ssh 公鑰添加到 github 賬號上,然后就可以正常拉取、推送代碼了 執(zhí)行生成 ssh 密鑰的命令, 會有交互性操作,提示讓輸入密碼, 直接一路回車即可 ssh-keygen 用于生成、管理、轉(zhuǎn)換認(rèn)證秘鑰 參數(shù): -t,type 指定要創(chuàng)建的秘鑰類型,可取值: rsa1(SSH-1)、rsa(SSH-2)、dsa(SSH-2) ``` ssh-keygen -t rsa ``` 查看生成的 SSH 公鑰 ``` cat ~/.ssh/id_rsa.pub ```  mac 系統(tǒng)生成 ssh 公鑰  #### 3. 在 github 上添加 SSH 公鑰 --- **前往個人中心設(shè)置 `Settings`**  **點擊左側(cè)欄目 `SSH and GPG keys`**  **將生成的 SSH 公鑰保存到 github 中, 建議標(biāo)題標(biāo)明 SSH 公鑰來源**  #### 4. 在 gitee 上添加 SSH 公鑰 ---  #### 5. 重新拉取項目 --- ``` git clone git@github.com:shinyboys/test.git ``` 