配置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

相关文章
|
1月前
|
开发工具 git
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
186 69
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
|
1月前
|
Devops Shell 网络安全
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
85 16
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
|
5月前
|
Shell 网络安全 开发工具
Git,GitHub,Gitee&IDEA集成Git
Git提交项目到GitHub简洁版、版本控制、安装、常用命令、分支、团队协作机制、Github、Gitee远程仓库、IDEA集成Git、IDEA集成Github、IDEA集成Gitee
|
6月前
|
jenkins Devops Java
jenkins学习笔记之十:配置Gitlab提交流水线
jenkins学习笔记之十:配置Gitlab提交流水线
|
6月前
|
网络安全 Windows
在Windows电脑上启动并配置SSH服务
在Windows电脑上启动并配置SSH服务
1486 0
|
6月前
|
监控 安全 Ubuntu
在Linux中,如何进行SSH服务配置?
在Linux中,如何进行SSH服务配置?
|
6月前
|
安全 网络协议 Shell
Github代码仓库SSH配置流程
这篇文章是关于如何配置SSH以安全地连接到GitHub代码仓库的详细指南,包括使用一键脚本简化配置过程、生成SSH密钥对、添加密钥到SSH代理、将公钥添加到GitHub账户以及测试SSH连接的步骤。
145 0
Github代码仓库SSH配置流程
|
6月前
|
Ubuntu Shell 网络安全
【Ubuntu】配置SSH
【Ubuntu】配置SSH
153 0
|
6月前
|
安全 Linux 网络安全
在Linux中,如何配置SSH以确保远程连接的安全?
在Linux中,如何配置SSH以确保远程连接的安全?
|
5月前
|
Docker 容器
Docker安装Gitlab和Gitlab-Runner并实现项目CICD
Docker安装Gitlab和Gitlab-Runner并实现项目CICD