软件工程

Git配置多个SSH-Key

本文主要是介绍Git配置多个SSH-Key,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

链接地址 https://gitee.com/help/articles/4229#article-header0

Git配置多个SSH-Key

背景

当有多个git账号时,比如:

a. 一个gitee,用于公司内部的工作开发;
b. 一个github,用于自己进行一些开发活动;

解决方法

  1. 生成一个公司用的SSH-Key

$ ssh-keygen -t rsa -C 'xxxxx@company.com' -f ~/.ssh/gitee_id_rsa
  1. 生成一个github用的SSH-Key

$ ssh-keygen -t rsa -C 'xxxxx@qq.com' -f ~/.ssh/github_id_rsa
  1. 在 ~/.ssh 目录下新建一个config文件,添加如下内容(其中Host和HostName填写git服务器的域名,IdentityFile指定私钥的路径)

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

4.用ssh命令分别测试

$ ssh -T git@gitee.com
$ ssh -T git@github.com



这篇关于Git配置多个SSH-Key的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!