刚在配置自己的Git ,弄完 SSH keys 后,自己的Git 可以提交了,发现公司的又不行了 😒
Goole 上搜了一下,解决了,总结一下使用方式。
- 先删除全局的 name 及 emali
git config --global --unset user.name
git config --global --unset user.email
然后给不同的 Git 配置不同的文件
- 公司的 git
~/.ssh/id_company 是文件地址 ssh-keygen -t rsa -f ~/.ssh/id_company -C "xxx.com"
- 然后回车,会让你设置密码,你可以设置自己的密码,默认是空 不需要密码 (
注意 这里设置的密码是在 git push 时用到的
)
- 然后回车,会让你设置密码,你可以设置自己的密码,默认是空 不需要密码 (
- 然后生成 key
- 打开 open ~/.ssh/id_company.pub 把里面的秘钥,粘贴到 公司 Git 上配置 ssh key 的位置
- 自己的 git
自己的就用默认的地址
ssh-keygen -t rsa -C "xxxx@gmail.com"
-
跟上面一样的步骤,在秘钥粘贴到 GitHub 上 ,位置如下
image.png
image.png
-
然后点击添加
image.png
image.png
- 在 .ssh 文件夹下创建 config 文件
cd ~/.ssh
touch config
vm config
- config 文件 —— 例如 我下面的配置
# github
Host github
Hostname github.com
User username
IdentityFile ~/.ssh/id_rsa
# company
Host aliyun
Hostname code.aliyun.com
User username
IdentityFile ~/.ssh/id_company_rsa
- 验证是否成功
ssh -T git@code.aliyun.com
- 成功
Welcome to GIT, xxx!
- 失败
Permission denied (publickey).
- 如果提醒失败 执行:
ssh-add ~/.ssh/id_company_rsa
- 执行上一步,第二天又失败了,执行
ssh-add -k ~/.ssh/id_company_rsa
- 在 git 项目中 分别 设置 config user.name 和 config user.email
git config user.name "xxxx"
git config user.email "xxxx"
网友评论