设置两个公钥
命令:设置了密钥文件名
第一个:ssh-keygen -t rsa -C "yourmail@xxx.com" 第二个:ssh-keygen -t rsa -f ~/.ssh/id_rsa_2 -C "yourmail@xxx.com"
结果图:
设置 git 映射
目的:使不同 Host 实际映射到同一个 HostName,但密钥文件不同。Host 前缀可自定义。
动作:编辑 ~/.ssh/config 文件
代码:#one Host github HostName github.com IdentityFile ~/.ssh/id_rsa ( 私钥名 ) User git # two Host self.github.com ( 自定义.github.com ) HostName github.com User git IdentityFile ~/.ssh/id_rsa_2
粘贴公钥
- 动作:将生成的 id_rsa_1.pub,id_rsa_2.pub 内容粘贴到仓库
测试 ssh 链接
代码:
ssh -T git@self.github.com (自定义.github.com) ssh -T git@github.com
成功结果显示:# Hi IEIT! You’ve successfully authenticated, but GitHub does not provide shell access.
克隆 github 到本地
- 命令:git clone git@自定义.github.com:git用户名/仓库.git
如果 git 上是 git@github.com:git用户名/仓库.git,
那么克隆时,是 git@自定义.github.com:git用户名/仓库.git
取消全局,单独设置
代码:
取消全局 用户名/邮箱 配置 git config –global –unset user.name git config –global –unset user.email 进入项目文件夹,单独设置每个repo 用户名/邮箱 git config user.email “xxxx@xx.com” git config user.name “xxxx”
重建 origin
命令
git remote rm origin git remote add origin git@(自定义.)github.com:git用户名/仓库.git
查看 git 相关信息
- 命令:git config –list
- 图: