本地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

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

相关推荐
WebInfra5 小时前
Rspack 1.5 发布:十大新特性速览
前端·javascript·github
6v6-博客6 小时前
P2P 远程桌面工具|免费开源内网穿透远程软件
运维·服务器
deeper_wind6 小时前
k8s-容器化部署论坛和商城服务(小白的“升级打怪”成长之路)
linux·运维·容器·kubernetes
勇往直前plus6 小时前
VMware centos磁盘容量扩容教程
linux·运维·centos
qq_441996057 小时前
SSH 反向隧道:快速解决服务器网络限制
服务器·网络·ssh
政安晨7 小时前
Ubuntu 服务器无法 ping 通网站域名的问题解决备忘 ——通常与网络配置有关(DNS解析)
linux·运维·服务器·ubuntu·ping·esp32编译服务器·dns域名解析
007php0078 小时前
Jenkins+docker 微服务实现自动化部署安装和部署过程
运维·数据库·git·docker·微服务·自动化·jenkins
路溪非溪9 小时前
嵌入式Linux驱动开发杂项总结
linux·运维·驱动开发
2501_920047039 小时前
nginx-限速-限制并发连接数-限制请求数
运维·nginx
SelectDB9 小时前
湖仓一体:小米集团基于 Apache Doris + Apache Paimon 实现 6 倍性能飞跃
数据库·开源·github