问题解决:git@github.com: Permission denied (publickey).

发布时间 2023-04-05 20:45:18作者: 早安陈老大

1. 检查 git global 配置

$ git config --global -l

检查 user.nameuser.email 是否正确,如果出现 fatal: unable to read config file '~/.gitconfig': No such file or directory ,执行一下命令初始化配置信息即可:

$ git config --global user.name "输入你的用户名"
$ git config --global user.email "输入你的邮箱地址"

2. 生成 public key

$ ssh-keygen -t rsa -C "你的邮箱地址"

默认情况下,生成密钥到 ~/.ssh/id_rsa.pub 文件。

3. 将生成的公钥添加到 github 中

登入你的 github 账户,打开 Settings > Access > SSH and GPG keys > New SSH key






~/.ssh/id_rsa.pub 的内容粘贴到 key 中,然后 Add SSH key


4. 验证是否成功

$ ssh -T git@github.com

可以看到 You've successfully authenticated, but GitHub does not provide shell access.