生成 Key
ssh-keygen -t rsa# 我把key生成在 ~/.ssh/github目录下,文件名为leonard-repo,文件如下:# ~/.ssh/github/leonard-repo# ~/.ssh/github/leonard-repo.pub# 查看公钥: cat ~/.ssh/github/leonard-repo.pub
在GitHub中退出 Key
网页github.com -> 某个仓库[ 假如为 leonard-repo] -> Setting -> Deploy keys
新建一个 key,把 leonard-repo.pub 这个公钥的内容复制到其中
本地设置
SSH 设置
编辑 ~/.ssh/config,退出以下内容
# leonard-repo 当初是 github.com的别名# 设置别名是避免烦扰其余仓库# 名字轻易起,然而须要和待会的 Git本地仓库设置 中的统一# github.com/leonard/leonard-repoHost leonard-repoHostname github.comidentityFile ~/.ssh/github/leonard-repoUser git
Git 本地仓库设置
编辑 我的项目/.git/config
把
[remote "origin"] url = git@github.com:leonard/leonard-repo.git fetch = +refs/heads/*:refs/remotes/origin/*
中的 github.com 改为 leonard-repo, 也就是上面这样
[remote "origin"] url = git@leonard-repo:leonard/leonard-repo.git fetch = +refs/heads/*:refs/remotes/origin/*