Github 每个项目配置ssh key

599 阅读1分钟

最近github的项目pull或者是push的时候,经常抽风的出现pull不下来或者是push不上去,所以决定把每个项目配置成ssh的方式

  1. ssh-keygen -t rsa -C "email", 这里不要忘记命名,否则会覆盖默认的

图片.png

  1. 然后把产生的公钥加入到github的项目中的Deploy keys中

图片.png

  1. 编辑 ~/.ssh/config, 添加进去如下配置
Host github.com-leetcode
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_leetcode
  1. 然后修改你项目下的git配置,打开 .git/config

[remote "origin"]

url = git@github-leedcode.com:zsjun/leetcode.git

fetch = +refs/heads/*:refs/remotes/origin/*

  1. finish