github上多个仓库设置单独的sshkey

356 阅读1分钟

一、 每个github账号下的多个仓库可以设置同一个sshkey

在右上角的profile那里设置,或直接点击链接  github.com/settings/ke…

二 、为每个仓库单独增加 sshkey

为每个仓库单独增加 sshkey

参考 docs.github.com/en/develope…

(1)创建 ~/.ssh/config

Host github.com-stock #这个是个本地解释的别名,真正的域名时下面的Hostname

Hostname github.com #真正的域名,这个是要能在dns解释的

IdentityFile=/home/user/.ssh/id_rsa_stock #对应的sshkey私钥


Host github.com-repo-1

Hostname github.com

IdentityFile=/home/user/.ssh/repo-1_deploy_key

(2)可以用ssh -T 来测试是否设置正确

ssh -T git@github.com-stock      #⚠️就是上面那个别名,别搞错了

Hi startmartin/stock! You've successfully authenticated, but GitHub does not provide shell access.

(3)设置本地仓库的remote url

git  remote set-url origin git@github.com-stock:startmartin/stock.git