Skip to content

git同时配置github gitee多个密钥

Terminal window
# GitHub
ssh-keygen -t ed25519 -C "i@lihaha.cn" -f ~/.ssh/github.ssh
# 码云
ssh-keygen -t ed25519 -C "i@lihaha.cn" -f ~/.ssh/gitee.ssh
Terminal window
# 比如 GitHub
https://github.com/settings/ssh/new
Terminal window
# 1. 创建一个 config 文件
~\.ssh\config
# 2. 添加配置
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee.ssh
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github.ssh
Terminal window
# 当出现用户名的时候代表成功
# GitHub
ssh -T git@github.com
Terminal window
# 设置全局
git config --global user.name "lihaha"
git config --global user.email "i@lihaha.cn"
# 设置单个仓库
git config user.name "lihaha"
git config user.email "i@lihaha.cn"
# 查看配置
git config --list