强调官方文档最可靠,百度踩坑很浪费时间,建议去寻找一手数据源头
github官方文档提供了帮助
-
第一步 查看密钥
如果您还没有 SSH 密钥,则必须生成新 SSH 密钥。 如果您不确定是否已有 SSH 密钥,请检查现有密钥。
ls -al ~/.ssh
-
生成密钥(如果已有跳过)
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
如果不是在 .ssh目录生成的,需要把密钥复制到当前用户下.ssh文件夹(这个文件夹是隐藏文件夹) -
将 SSH 密钥添加到 ssh-agent
确保 ssh-agent 正在运行
$ ssh-add ~/.ssh/id_rsa
若执行ssh-add 是出现这个错误:Could not open a connection to your authentication agent,则先执行如下命令即可:
ssh-agent bash
-
将 SSH 密钥添加到 GitHub 帐户
官方文档 https://help.github.com/cn/articles/adding-a-new-ssh-key-to-your-github-account