· 1 min read
配置多个 Git 仓库的 SSH 权限
Git
- 跳转至 ssh 配置路径,通常默认为
~/.ssh - 创建 ssh 密钥对,按照提示创建文件名(eg:repo1-deploy-key、repo2-deploy-key),简易命令用
./ssh-keygen即可,默认创建 rsa 密钥对,也可以通过参数自定义,例如./ssh-keygen -t ed25519 -C username等 - eval
ssh-agent -s - ssh-add repo1-deploy-key repo2-deploy-key
- 复制 filename.pub 中的内容
- 粘贴至 Git 仓库的 Settings—Deploy Keys—Add deploy key 中
- 修改
~/.ssh/config,参考如下
Host repo1.github.com
HostName github.com
AddKeysToAgent yes
IdentityFile ~/.ssh/repo1-deploy-key
Host repo2.github.com
HostName github.com
AddKeysToAgent yes
IdentityFile ~/.ssh/blog-repo
- 分别修改 repo1、repo2 目录下
.git/config中的 url,参考如下
//url = git@github.com:username/repo1.git
url = git@repo1.github.com:username/repo1.git
Failed to connect to github.com port 443: Timed out
将 .git/config 文件中的 https url 修改为 Git 仓库的 ssh rul。