[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 ``` 