美文网首页
GitHub 配置 SSH

GitHub 配置 SSH

作者: 远方竹叶 | 来源:发表于2020-06-29 14:47 被阅读0次

最近在使用 git 时,出现报错提示

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.

这个是因为你GitHub的KEY过期了。长期不clone代码导致的。
进入~/.ssh 目录。删除 known_hosts 里面过期的git账号

vi ~/.ssh/known_hosts

然后生成一对新的公钥、私钥。说白了这就是SSH免密登录

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

然后注意!在Mac下。我们要做这个操作。将SSH 添加到ssh-agent!

1、在后台启动 ssh-agent

eval "$(ssh-agent -s)"
> Agent pid 18995

2、修改~/.ssh/config文件(这个是Mac系统大于 10.12.2 的)

vi ~/.ssh/config

然后编辑内容,你私钥的名字和路径

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/github_yuanfangzhuye

3、将您的SSH私钥添加到ssh-agent并将密码短语存储在钥匙串中

ssh-add -K ~/.ssh/id_rsa

4、最后一步,Copy 我们的公钥内容,这里也可以用命令

pbcopy < ~/.ssh/github_yuanfangzhuye.pub

代开 https://github.com 点击头像 => Settings => SSH and GPG keys,粘贴

相关文章

网友评论

      本文标题:GitHub 配置 SSH

      本文链接:https://www.haomeiwen.com/subject/mtpofktx.html