gitee pull 总是需要用户名和密码,该如何设置?
使用 SSH 协议连接 Gitee 可以避免每次输入用户名密码的问题。
·
注意:不是使用github而是gitee
使用 SSH 协议连接 Gitee 可以避免每次输入用户名密码的问题。
1. 生成 SSH 密钥对(如果已有可跳过)
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 配置文件
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 连接
ssh -T git@gitee.com
# 成功会显示:
# Hi xxx! You've successfully authenticated, but GITEE.COM does not provide shell access.
查看当前远程地址
git remote -v
如果显示 HTTPS 地址,需要修改为 SSH 地址
git remote set-url origin git@gitee.com:username/repository.git
更多推荐
所有评论(0)