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
![](https://img.haomeiwen.com/i14245154/13a448f9df843d49.png)
2. 生成 github 的秘钥
命令行输入: ssh-keygen -t rsa -C "你的邮箱"
,连续三次回车,生成秘钥
![](https://img.haomeiwen.com/i14245154/cb6e18ad30d29ebb.png)
秘钥和公钥的路径为:
~/.ssh/id_rsa ~/.ssh/id_rsa.pub
![](https://img.haomeiwen.com/i14245154/018c158b03291663.png)
3 在 github 配置公钥
复制公钥,粘贴到github的公钥列表中。
![](https://img.haomeiwen.com/i14245154/3d7fa554df47e439.png)
![](https://img.haomeiwen.com/i14245154/c0d4040fa52c0206.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
可以查看配置的信息
![](https://img.haomeiwen.com/i14245154/b54e5a9937ff48c3.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]-----+
![](https://img.haomeiwen.com/i14245154/daf89d1544c6fee1.png)
秘钥和公钥的路径为:
~/.ssh/hktest ~/.ssh/hktest.pub
我这里直接保存在
/home/rina/
![](https://img.haomeiwen.com/i14245154/39ca9f2fa101492e.png)
3. 配置gitlab_company公钥
![](https://img.haomeiwen.com/i14245154/1bb923aa1cd461f2.png)
配置完成
![](https://img.haomeiwen.com/i14245154/2914fad5e3661ee6.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 可正常拉取代码
![](https://img.haomeiwen.com/i14245154/34bec2abdd388aff.png)
参考文档