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.
相关推荐
SNOWPIAOP1 小时前
git status 出现中文乱码的解决方案等
git·乱码·postgres
qq_4352879212 小时前
第9章 夸父逐日与后羿射日:死循环与进程终止?十个太阳同时值班的并行冲突
java·开发语言·git·死循环·进程终止·并行冲突·夸父逐日
AIMath~18 小时前
Git 子模块(Submodule)目录结构清除实战复盘
git
切糕师学AI19 小时前
Ubuntu 下 Git 完全使用指南
linux·git·ubuntu
一袋米扛几楼9821 小时前
【Git】规范化协作:详解 GitHub 工作流中的 Issue、Branch 与 Pull Request 最佳实践
前端·git·github·issue
尘埃落定wf1 天前
# GitHub CLI:告别繁琐的 Git 命令,让开发更高效
git·github
恋喵大鲤鱼1 天前
git clone
git·git clone
金牛IT1 天前
Gogs 轻量级 Git 服务器搭建与使用
运维·服务器·git
Qres8211 天前
Git安装记录
git
wj3055853781 天前
Codex + Git 开发环境配置指南(WSL版)
linux·运维·git