注意:不是使用github而是gitee
使用 SSH 协议连接 Gitee 可以避免每次输入用户名密码的问题。
1. 生成 SSH 密钥对(如果已有可跳过)
bash
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# 执行后会提示:
# - 保存位置:按 Enter 使用默认 (~/.ssh/id_rsa)
# - 设置密码:可选,设置后每次使用需要输入密码
2. 将公钥添加到 Gitee
cat ~/.ssh/id_rsa.pub
在 Gitee 添加公钥:
-
登录 Gitee → 右上角头像 → 设置
-
左侧选择 SSH 公钥
-
标题:任意名称(如 "My MacBook")
-
公钥:粘贴刚才复制的公钥内容
-
点击 确定
3. 编辑 SSH 配置文件
bash
vim ~/.ssh/config
# 添加以下内容:
Host gitee.com
HostName gitee.com
Port 22
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
TCPKeepAlive yes
ServerAliveInterval 30
ServerAliveCountMax 6
4. 测试 SSH 连接
bash
ssh -T git@gitee.com
# 成功会显示:
# Hi xxx! You've successfully authenticated, but GITEE.COM does not provide shell access.