Git 配置多账号

2024-04-17  本文已影响0人  Rinaloving

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

参考文档

上一篇 下一篇

猜你喜欢

热点阅读