ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

【git基础】Windows下Git多账号配置,同一电脑多个ssh-key的管理

2021-08-02 20:01:45  阅读:210  来源: 互联网

标签:git Windows gitlab rsa github Git ssh key id


 

step1: 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

step2: 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文本文件,完成对应的git配置;

每个账号单独配置一个Host,每个Host要取一个别名,每个Host主要配置HostNameIdentityFile两个属性即可

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 happyamyhope! You've successfully authenticated, but GitHub does not provide shell access.

参考

1. Windows下Git多账号配置,同一电脑多个ssh-key的管理

 

标签:git,Windows,gitlab,rsa,github,Git,ssh,key,id
来源: https://www.cnblogs.com/happyamyhope/p/15090335.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有