gitee pull 总是需要用户名和密码,该如何设置?

注意:不是使用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 添加公钥:

  1. 登录 Gitee → 右上角头像 → 设置

  2. 左侧选择 SSH 公钥

  3. 标题:任意名称(如 "My MacBook")

  4. 公钥:粘贴刚才复制的公钥内容

  5. 点击 确定

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.
相关推荐
A_Lonely_Cat43 分钟前
记一次 GitHub 幽灵协作者大清洗:强制重写 Git 历史与穿透 CDN 缓存实践
git·github
和你看星星2 天前
Git rerere:让重复冲突只解决一次
git
嘻嘻仙人6 天前
Ubuntu中 git上传自己的项目和二次上传一般流程
git·github
Patrick_Wilson6 天前
Squash Merge 的血缘陷阱:为什么删掉的代码又活了过来
前端·git·程序员
沉浸学习的匿名网友6 天前
什么是 .gitignore?为什么每个 Git 项目几乎都离不开它?
前端·git
深海鱼在掘金7 天前
Git 完全指南 —— 第3章:理解工作区、暂存区、版本库三个核心
git
江华森7 天前
Git 基础筑基:从原理到团队协作的全栈实战
git
JakeJiang7 天前
Git 必备命令指南:从日常高频到项目开发实战
git
叫我少年8 天前
Windows 中安装 git
git
深海鱼在掘金13 天前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git