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.
相关推荐
爱学英语的程序员24 分钟前
Git 提交 LF will be replaced by CRLF the next time Git touches it 报错
git
qq_339191141 小时前
服务器git pull每次都要输入密码,linux 设置git登录,linux设置git只输入一次账户密码
git
一颗小行星!7 小时前
快速理解 Git submodule
git
A-Jie-Y9 小时前
Git基础-核心概念与常用命令
git
夜珀10 小时前
Git基础修炼手册:在AtomGit上玩转版本控制
git
golang学习记10 小时前
Zed IDE官宣新招:Git Graph 正式支持!
ide·git
要记得喝水10 小时前
适用于 Git Bash 的脚本,批量提交和推送多个仓库的修改
git·elasticsearch·bash
AI_Claude_code11 小时前
专栏导论:开源项目贡献的价值与Git工作流全景图
git·开源
never forget shyang11 小时前
CCS20.2.0使用教程
c语言·git·单片机
lifewange20 小时前
常用的Git命令有哪些?
git