美文网首页
Git 配置多账号

Git 配置多账号

作者: Rinaloving | 来源:发表于2024-04-17 09:52 被阅读0次

配置 github账号

1. 配置账号

git config --global user.email xxx@163.com 
git config --global user.name xxx
 

配置成功后,git config -l可以查看配置的信息

git config -l 
image.png
2. 生成 github 的秘钥

命令行输入: ssh-keygen -t rsa -C "你的邮箱",连续三次回车,生成秘钥

image.png
秘钥和公钥的路径为:~/.ssh/id_rsa ~/.ssh/id_rsa.pub
image.png
3 在 github 配置公钥

复制公钥,粘贴到github的公钥列表中。


image.png
image.png

配置成功后,测试配置是否正确。命令行输入:

ssh git@github.com

如果看到 You've successfully authenticated则配置成功。

配置内网

1. 配置内网服务器的用户名和邮箱
git config --global user.email 142xxxx@qq.com
 
git config --global user.name xxxx

配置成功后,git config -l 可以查看配置的信息

image.png
2. 生成 gitlab_company 秘钥

命令行输入:ssh-keygen -t rsa -C "你的邮箱",但在首次提示时,即命令行提示:Enter file in which to save the key()中输入你要保存的路径和文件名,建议保存在~/.ssh/下,不要与之前配置github的秘钥重名。

rina@rina-desktop:~$ ssh-keygen -t rsa -C "14xxxx456@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/rina/.ssh/id_rsa): gitlab_company
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in gitlab_company
Your public key has been saved in gitlab_company.pub
The key fingerprint is:
SHA256:HT0EjhRSND9RtG1wKbhAbHppYaZoAFfkwv6Gl3RNKKw 14xxxx456@qq.com
The key's randomart image is:
+---[RSA 3072]----+
|...oo .=B.o== .. |
| o.o   +B=.+.=.  |
|  o.+..*o+=.+.o  |
| . oo.oo+..o o   |
|  E.. .oS .      |
|   + o           |
|  . =            |
|   o             |
|                 |
+----[SHA256]-----+

image.png
秘钥和公钥的路径为:~/.ssh/hktest ~/.ssh/hktest.pub
我这里直接保存在 /home/rina/
image.png
3. 配置gitlab_company公钥
image.png

配置完成


image.png
4. 新建config 文件

在目录 ~/下新建config文件:vi config

# http://git.968382.com:7931/
 
Host git.968382.com:7931/
 
HostName git.968382.com:7931/
 
PreferredAuthentications publickey
 
IdentityFile ~/gitlab_company
 
User cfl

保存文件,重启 ubuntu

再次输入git pull 可正常拉取代码


image.png

参考文档

相关文章

  • windows系统下配置多个git账号以及SSH

    本文以配置github.com账号和git.oschina.net账号来逐步演示在Windows环境下配置Git多...

  • git多账号配置

    git多账号配置 1. 生成ssh密钥 出现 Could not open a connection to you...

  • git多账号配置

    由于公司gitlab账号是ssh:git@...::818这种情况的所以今天按照文档一直没配置成功,然后增加了一个...

  • git多账号配置

    工作中往往我们会遇到这种情况, 公司给了邮箱, 采用类似gitlab之类的git服务托管商, 而我们又拥有自己的g...

  • git多账号配置

    在实际工作中,常常会遇到多个git帐号(即多个远程仓库)的情况,这时候如果只有一个SSH-key则无法满足现有要求...

  • Git 多账号配置

    问题描述 git是目前使用的非常广泛的一个开源的分布式版本控制系统,大部分公司都在使用,然后大家又有自己的Gith...

  • git 多账号配置

    生成新密钥 注册新的私钥 查看私钥列表 新建config文件

  • git多账号配置

    公司用的是icode,自己的项目用的是github托管,用户名和证书不一样,需要配置两份 有多种方式: 生成con...

  • git本地配置多账号

    一般为了方便本地git 同时支持公司的账号以及自己的github账号, 需要配置多账号支持,假设之前已经配置好了工...

  • 二、配置多个git仓库和账户

    git多仓库配置  自己在github建了个仓库,然后配置访问不了,上网查了下怎么用不同账号在本地配置多个git仓...

网友评论

      本文标题:Git 配置多账号

      本文链接:https://www.haomeiwen.com/subject/qbmsxjtx.html