配置gitlab/github/gitee多个ssh-key

简介: 配置gitlab/github/gitee多个ssh-key

gitlab的密钥配置


  1. git bash执行下面命令生成ssh公钥和私钥对


ssh-keygen -t rsa -C '你的邮箱' 一路回车


  1. 查看公钥内容:cat ~/.ssh/id_rsa.pub (~用户目录)
  2. 配置远程仓库公钥:个人头像 -> settings -> SSH And GPG Key -> 点击 新增SSH Key按钮 -> 复制公钥



f83b5ce4ead54833951da45fbef5f570.png


配置多个ssh-key


  1. 为gitlab生成一对秘钥ssh key


ssh-keygen -t rsa -C 'yourEmail@xx.com' -f ~/.ssh/gitlab-rsa


  1. 为github生成一对秘钥ssh key


ssh-keygen -t rsa -C 'yourEmail2@xx.com' -f ~/.ssh/github-rsa


添加私钥


ssh-add ~/.ssh/gitlab-rsa 
ssh-add ~/.ssh/github-rsa


执行ssh-add时提示"Could not open a connection to your authentication agent",可以现执行命令:

ssh-agent bash
# 确私钥列表
ssh-add -l
# 清空私钥列表
ssh-add -D
exit


再运行ssh-add命令


在~/.ssh下touch config,配置多个不同的ssh key


# gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab-rsa 
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github-rsa 
# Host和HostName填写git服务器的域名,IdentityFile指定私钥的路径

测试


ssh -T -v git@[config配置的host值]
ssh -T git@github.com
ssh -T git@gitlab.com
ssh -T git@gitee.com


Hi stefzhlg! You’ve successfully authenticated, but GitHub does not provide shell access

相关文章
|
2月前
|
开发工具 git
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
229 69
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
|
2月前
|
Devops Shell 网络安全
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
127 16
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
|
4月前
|
Linux 网络安全 开发工具
IDEA如何配置git和github
【11月更文挑战第14天】本指南详细介绍了如何在 IntelliJ IDEA 中配置 Git 和 GitHub,包括检查和设置 Git 路径、测试配置,以及通过 SSH 或 HTTPS 方式配置 GitHub 仓库的具体步骤。完成配置后,用户可在 IDEA 中轻松进行版本控制操作。
684 0
|
5月前
|
JavaScript Linux Windows
Typora图床配置(用自带的 PicGo-Core(command line) 插件GitHub
Typora图床配置(用自带的 PicGo-Core(command line) 插件GitHub
|
6月前
|
Shell 网络安全 开发工具
Git,GitHub,Gitee&IDEA集成Git
Git提交项目到GitHub简洁版、版本控制、安装、常用命令、分支、团队协作机制、Github、Gitee远程仓库、IDEA集成Git、IDEA集成Github、IDEA集成Gitee
|
7月前
|
安全 网络协议 Shell
Github代码仓库SSH配置流程
这篇文章是关于如何配置SSH以安全地连接到GitHub代码仓库的详细指南,包括使用一键脚本简化配置过程、生成SSH密钥对、添加密钥到SSH代理、将公钥添加到GitHub账户以及测试SSH连接的步骤。
176 0
Github代码仓库SSH配置流程
|
7月前
|
jenkins Devops Java
jenkins学习笔记之十:配置Gitlab提交流水线
jenkins学习笔记之十:配置Gitlab提交流水线
|
7月前
|
Linux C++ Docker
【Azure Developer】在Github Action中使用Azure/functions-container-action@v1配置Function App并成功部署Function Image
【Azure Developer】在Github Action中使用Azure/functions-container-action@v1配置Function App并成功部署Function Image
|
存储 运维 安全
【运维知识高级篇】一篇文章带你搞懂GitHub基础操作!(注册用户+配置ssh-key+创建项目+创建存储库+拉取代码到本地+推送新代码到Github)
【运维知识高级篇】一篇文章带你搞懂GitHub基础操作!(注册用户+配置ssh-key+创建项目+创建存储库+拉取代码到本地+推送新代码到Github)
391 0
|
10月前
|
网络安全
github或gitee配置ssh
github或gitee配置ssh
86 0