当前位置: 首页 > news >正文

git生成gitee和github两个不同的公钥

配置多个公钥

Windows 用户建议使用 Windows PowerShell 或者 Git Bash,在 命令提示符 下无 cat 和 ls 命令。

1、生成公钥文件:

通过命令 ssh-keygen 生成 SSH Key:

ssh-keygen -t rsa -C "Gitee SSH Key" -f ~/.ssh/gitee_bealei_rsassh-keygen -t rsa -C "Github SSH Key" -f ~/.ssh/github_bealei_rsa
  • -t key 类型
  • -C 注释
  • -f 指定用来保存密钥的文件名

输出,如:

Bealei@Y7000 MINGW64 /d/Desktop
$ ssh-keygen -t rsa -C "Gitee SSH Key" -f ~/.ssh/gitee_bealei_rsa
Generating public/private rsa key pair.
/c/Users/Administrator/.ssh/gitee_bealei_rsa already exists.
Overwrite (y/n)?Bealei@Y7000 MINGW64 /d/Desktop
$ ssh-keygen -t rsa -C "Gitee SSH Key" -f ~/.ssh/gitee_bealei_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/gitee_bealei_rsa
Your public key has been saved in /c/Users/Administrator/.ssh/gitee_bealei_rsa.pub
The key fingerprint is:
SHA256:zTjk4lQJkyjatPJa8fucucXVkBPtV4o2LWj3CkcLfW4 Gitee SSH Key
The key's randomart image is:
+---[RSA 3072]----+
|     .o.  ..     |
|  o . .o . o.   .|
| + o    + ++ o o |
|o +    + +++X =  |
| o o  o S.+=.O   |
|  o .o o o. o E  |
| o   .. o  o o   |
|.   .. +    .    |
|     .*.         |
+----[SHA256]-----+
Bealei@Y7000 MINGW64 /d/Desktop
$ ssh-keygen -t rsa -C "Github SSH Key" -f ~/.ssh/github_bealei_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/github_bealei_rsa
Your public key has been saved in /c/Users/Administrator/.ssh/github_bealei_rsa.pub
The key fingerprint is:
SHA256:LveFZoIaZF5OdMHtNf5hb7VaH+2dhqPXiOxuIFT2QJw Github SSH Key
The key's randomart image is:
+---[RSA 3072]----+
|       .+o.      |
|        .E. o    |
|      . +.oo .   |
|     . o  ... o .|
|    o + S    o o+|
|   + + + . .  .++|
|    o + = * o *o=|
|     o o = = * ++|
|    .     =+o o  |
+----[SHA256]-----+

生成如下文件,其中gitee_bealei_rsa.pub为公钥,gitee_bealei_rsa为私钥:

在这里插入图片描述

2、读取公钥文件:
cat ~/.ssh/gitee_bealei_rsa.pub

输出,如:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAB********************Zm8= Gitee SSH Key

复制终端输出的公钥。

cat ~/.ssh/github_bealei_rsa.pub

输出,如:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAB********************Igs= Github SSH Key

复制终端输出的公钥。

3、配置仓库公钥

将生成的公钥,配置到gitee及github各自账户下

4、配置config文件

在.ssh目录下新建config.txt文件,编辑配置内容如下,去掉后缀保存文件名为config

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_bealei_rsa# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_bealei_rsa
5、测试连接

在本地git 的命令行中测试连接两种仓库,连接成功

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

输出:

# gitee
Bealei@Y7000 MINGW64 /d/Desktop
$ ssh -T git@gitee.com
Hi bealei(@bealei)! You've successfully authenticated, but GITEE.COM does not provide shell access.# github
Bealei@Y7000 MINGW64 /d/Desktop
$ ssh -T git@github.com
Hi bealei! You've successfully authenticated, but GitHub does not provide shell access.
http://www.lryc.cn/news/216040.html

相关文章:

  • 基于SSM的同学录网站
  • 第十五节——观察者watch
  • tauri 访问静态资源,响应头为Content-Type:‘text/html‘
  • 【佳学基因检测】Node.js中如何读取并调用内容
  • java根据音频流或者音频的地址获取分贝的工具类
  • Pycharm出现的一些问题和解决办法
  • 进程优先级(nice值,top指令),独立性,竞争性,进程切换(时间片),抢占与出让,并发并行概念
  • 若依微服务集成Mybatis-plus详细教程
  • WebSocket:实现实时双向通信的利器
  • 【uniapp】html和css-20231031
  • Docker Tomcat 搭建文件服务器
  • 无感刷新 token
  • 【MISRA C 2012】Rule 2.6 函数不应该包含未使用的标签声明
  • Ubuntu:使用apache2部署Vue开发的网站
  • 使用IO完成端口实现简单回显服务器
  • 【ROS】Nav2源码之nav2_behavior_tree详解
  • SpringBoot---myBatis数据库操作
  • 力扣541.反转字符串II
  • 撕掉Hadoop标签,Cloudera未来可期吗?
  • 排序算法(1)
  • Top 5 Cutting-edge technology examples 2023
  • 【算法|滑动窗口No.3】leetcode3. 无重复字符的最长子串
  • 元素的水平居中和垂直几种方案
  • JS和JQuery的区别
  • 延时摄影视频制作工具 LRTimelapse mac中文版特点介绍
  • Mac电脑怎么运行 Office 办公软件
  • FPGA 如何 固化程序到 FLASH中
  • 电源管理(PMIC)MAX20428ATIA/VY、MAX20428ATIC/VY、MAX20428ATIE/VY适合汽车ADAS应用的开关稳压器
  • 十年JAVA搬砖路——Linux搭建Ldap服务器。
  • 论文 辅助笔记:t2vec train.py