本地github ssh多账号问题

哈哈,看来你的 老账号 xxxxx 还在"阴魂不散" ,而且你现在用的是 HTTPS 方式 而不是 SSH,所以 SSH 配置对它无效!

别急,我们有两种方法解决:


🔧 解决方案 1:改用 SSH 方式(推荐)

既然你已经配好了 SSH 多账号,那就直接 把远程仓库地址从 HTTPS 改成 SSH:

  1. 查看当前远程地址(确认是 HTTPS):

    bash 复制代码
    git remote -v

    输出可能是:

    复制代码
    origin  https://github.com/xxxxxxxx/xxx.git (fetch)
    origin  https://github.com/xxxxxxxx/xxx.git (push)
  2. 修改为 SSH 地址 (用你 ~/.ssh/config 里定义的 Host):

    bash 复制代码
    git remote set-url origin git@github.com-newaccount:xxxxxxxxx/elm.git

    (⚠️ github.com-newaccount 要和你 ~/.ssh/config 里的 Host 名一致!)

  3. 再 push 试试:

    bash 复制代码
    git push origin main

    ✅ 现在应该不会报 xxxxxxx 的权限问题了!


🔧 解决方案 2:清除 Git 的 HTTPS 认证缓存(如果仍想用 HTTPS)

如果你 非要继续用 HTTPS,那就得清除 Git 的旧账号缓存:

Windows(Git Credential Manager)

  1. 打开 Windows 凭据管理器(Win + S → 搜索"凭据管理器")。
  2. 进入 Windows 凭据 → 普通凭据。
  3. 找到 git:https://github.com 相关的条目,删除它。

Mac / Linux(Git 凭据缓存)

运行:

bash 复制代码
git config --global --unset credential.helper

或者手动清除缓存:

bash 复制代码
git credential reject <<EOF
protocol=https
host=github.com
EOF

然后重新 push,会弹出 GitHub 登录窗口

这时输入 新账号的用户名和密码(或 Personal Access Token) 即可。


💡 终极建议:尽量用 SSH!

  • HTTPS 每次 push 都可能要输密码(除非存了 PAT)。
  • SSH 配置好后 一劳永逸,还能多账号切换。

🚀 现在再试试 git push,应该没问题了吧?

如果还不行,请提供:

  1. git remote -v 的输出
  2. cat ~/.ssh/config 的内容
  3. 你用的 Git 版本(git --version)

我来帮你 精准"捉鬼"!👻🔫

相关推荐
2401_8724187810 分钟前
Windows服务器:错误 403 - 禁止访问:本地 FTP 上传文件到网站服务器后提示无访问权限
运维·服务器·windows
吴声子夜歌26 分钟前
Nginx应用与运维——Nginx在Kubernetes中的应用(二)
运维·nginx·kubernetes
Ruiery9 小时前
Linux 6.6内核 CPU 深度解析(七):调度器启动 — 从单核到多核,调度器分阶段点亮
linux·运维·服务器
50万马克的面包9 小时前
CSDN-栈队列数组-知识点整理
linux·运维·服务器
MicrosoftCloud10 小时前
用户权限 04|/etc/sudoers 安全配置:从最小授权到「别把 ALL 随便给人」
运维·安全·ubuntu·sudo·sudoers
꯭自꯭闭꯭11 小时前
达梦事物特性及MVCC
linux·运维·数据库
亚川楼宇自控系统数据中心厂家12 小时前
实验室智能化管理系统|人环物智一体化管控平台
运维
zmsup14 小时前
Agent 上下文调优:结合 OpsArk 运维智能体,设计模型每一步真正需要的信息
运维·agent·上下文压缩·运维智能体·上下文调优
ianzh15 小时前
workbuddy-to-dsh使用教程
github
YahirQ15 小时前
技术博客一键多发实战:基于 GitHub Actions 与双引擎的自动化发布流水线
github