git多用户设置方法
git多用户设置
生成ssh-keygen
通过ssh生成key(windows环境下,需要使用git bash)
注意:需要切换到用户目录进行操作(windows切换到用户目录)
$ ssh-keygen -t rsa -C "你的git帐号邮箱"
Generating public/private rsa key pair.
## 这里输入存储rsa文件的名称(多用户需要填写不同的名字)↓
Enter file in which to save the key (/d/Users/feng/.ssh/id_rsa):id_rsa_aliyun
## 这里设置密码(可不填)↓
Enter passphrase (empty for no passphrase):
## 重复密码(可不填)↓
Enter same passphrase again:
创建配置文件config
在~/.ssh目录下找到config文件(如果没有则创建一个,windows系统下目录地址为:C:\Users\你的用户名\\.ssh)gitlab
# 默认配置,一般可以省略
# 主机名字,不能重名
Host github.com
Hostname github.com
User 你的名称
Identityfile ~/.ssh/id_rsa
# 第二个配置
# 主机名字,不能重名
Host code.aliyun.com
# 主机所在域名或IP
HostName code.aliyun.com
# 用户名称
User 你的名称
# 私钥路径
IdentityFile ~/.ssh/id_rsa_aliyun
在git仓库中配置ssh-keys
查看.pub文件中的公钥,
cat id_rsa.aliyun.pub
并添加到仓库中的ssh-keys中(管理后台的sshKeys中)
测试
测试命令:
ssh -T git@code.aliyun.com
结果:
Welcome to GIT, 麦奇!
如果看到此命令,恭喜配置成功!!
遇到问题:
目前phpstorm无法使用内置的git进行更新提交代码
错误提示为:Could not read from remote repository.
解决办法:设置仓库级别的用户名和邮箱(必须切换到当前项目下)
设置方法:
切换到单个项目中设置相对应的账户和邮箱
// 设置仓库的user.email和user.name
git config user.email "你的邮箱"
git config user.name "你的用户名"
Everything Will Be Ok !
欢迎关注公众号:山脚下的乌龟