【git基础】Windows下Git多账号配置,同一电脑多个ssh-key的管理
step1: gitlab,生成gitlab网站的公钥私钥;
$ ssh-keygen -t rsa -C xxx.yy@zzz.com Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/xxx/.ssh/id_rsa): id_rsa_gitlab Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in id_rsa_gitlab Your public key has been saved in id_rsa_gitlab.pub
注意,【Enter passphrase (empty for no passphrase)】设置密码;
step2: github,生成github网站的公钥私钥;
$ ssh-keygen -t rsa -C xxx@163.com Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/zzz/.ssh/id_rsa): id_rsa_github Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in id_rsa_github Your public key has been saved in id_rsa_github.pub
step3: 将得到的id_rsa/id_rsa.pub文件保存在git默认访问的.ssh的目录;
$ ls config id_rsa_github id_rsa_github.pub id_rsa_gitlab id_rsa_gitlab.pub known_hosts known_hosts.old
step4: 将github/gitlab的公钥分别上传到对应的服务器;
github:setting / SSH and GPG keys;
gitlab:setting / SSH keys
step5: 在.ssh目录创建config文件(直接vi config然后添加配置内容即可),完成对应的git配置;
每个账号单独配置一个Host,每个Host要取一个别名,每个Host主要配置HostName和IdentityFile两个属性即可
Host的名字可以取为自己喜欢的名字,不过这个会影响git相关命令,例如:
Host mygithub 这样定义的话,命令如下,即git@后面紧跟的名字改为mygithub;
HostName 这个是真实的域名地址 IdentityFile 这里是id_rsa的地址 PreferredAuthentications 配置登录时用什么权限认证--可设为publickey,password publickey,keyboard-interactive等 User 配置使用用户名
example:git clone git@mygithub:happyamyhope/IPM.git
# GitLab.xxx.yy Host gitlab.xxx.yy HostName gitlab.xxx.yy IdentityFile C:\Users\zzz\.ssh\id_rsa_gitlab RSAAuthentication yes PreferredAuthentications publickey User aaa.bbb@ccc.com # Github.com Host github.com HostName github.com IdentityFile /c/Users/zzz/.ssh/id_rsa_github RSAAuthentication yes PreferredAuthentications publickey User ddd@163.com
注意不同网站的名称是否正确;
step6:测试;
$ ssh -T git@github.com /c/Users/zzz/.ssh/config line 6: Unsupported option "rsaauthentication" /c/Users/zzz/.ssh/config line 13: Unsupported option "rsaauthentication" Enter passphrase for key '/c/Users/zzz/.ssh/id_rsa_github': Hi ddd! You've successfully authenticated, but GitHub does not provide shell access.
其他网站类似,比如
1 | ssh -T git@gitlab.abc.ai |
注意,ubuntu系统的配置过程几乎一样的!
step7: 不同平台帐号的管理和使用;
因为存在双/多账户,需要通过Git配置不同账户的用户和邮箱,这里采取GitLab用全局用户名和邮箱配置,而GitHub针对每个clone到本地的项目进行单独的用户名和邮箱配置,避免冲突。
1)配置全局的用户名和邮箱;
// 将GitLab设置为全局 git config --global user.name "gitlab" git config --global user.email "gitlab@126.com"
2)为GitHub上的每个repository/项目单独设置用户名和邮箱;
// 注意:下述命令要到每个本地GitHub项目目录下执行 git config user.name "github" git config user.email "github@126.com"
3)最后可以进行代码的修改,拉取、提交、push等,验证配置是否成功。
全局配置好像不管用啊,需要在每个git项目下单独设置用户名和邮箱;
参考
1. Windows下Git多账号配置,同一电脑多个ssh-key的管理;
完
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
2017-08-02 人脸对齐matlab实现-FaceAlignment 3000fps