git多用户配置
·
已经配置了github用户,现在想配置gitee
在 Windows 上配置 SSH 多账户的步骤如下:
1. 生成 Gitee 专用 SSH 密钥
打开 Git Bash 或 命令提示符,执行:
ssh-keygen -t rsa -C "your_email@gitee.com" -f C:/Users/你的用户名/.ssh/id_rsa_gitee
2. 将公钥添加到 Gitee
复制公钥内容:
cat ~/.ssh/id_rsa_gitee.pub
或者在文件管理器中打开 C:\Users\你的用户名\.ssh\id_rsa_gitee.pub,用记事本复制内容。
登录 Gitee → 设置 → SSH 公钥 → 粘贴公钥。
3. 创建 SSH 配置文件
在 C:\Users\你的用户名\.ssh\` 目录下创建config` 文件(无后缀名)。
用记事本或 VS Code 编辑,内容如下:
# GitHub
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
User git
# Gitee
Host gitee.com
HostName gitee.com
IdentityFile ~/.ssh/id_rsa_gitee
User git
Windows 路径说明:
-
~/.ssh/在 Windows 中对应C:\Users\你的用户名.ssh -
也可以使用绝对路径:
IdentityFile C:/Users/你的用户名/.ssh/id_rsa_gitee
4. 测试连接
# 测试 Gitee
ssh -T git@gitee.com
# 测试 GitHub
ssh -T git@github.com
成功时会显示相应的欢迎信息。
更多推荐


所有评论(0)