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

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

相关推荐
寻月隐君1 小时前
想用 Rust 开发游戏?这份超详细的入门教程请收好!
后端·rust·github
Otaku love travel1 小时前
实施运维文档
运维·windows·python
basketball6162 小时前
Linux C 管道文件操作
linux·运维·c语言
浩浩测试一下2 小时前
Windows 与 Linux 内核安全及 Metasploit/LinEnum 在渗透测试中的综合应用
linux·运维·windows·web安全·网络安全·系统安全·安全架构
将心ONE3 小时前
使用 lstrip() 和 rstrip() 方法
运维·服务器
G_whang3 小时前
centos7 安装jenkins
运维·jenkins
SoFlu软件机器人4 小时前
Cursor、飞算JavaAI、GitHub Copilot、Gemini CLI 等热门 AI 开发工具合集
人工智能·github·copilot
言之。4 小时前
借助ssh实现web服务的安全验证
运维·安全·ssh
Two_brushes.5 小时前
【linux网络】深入理解 TCP/UDP:从基础端口号到可靠传输机制全解析
linux·运维·服务器
FJW0208145 小时前
【Linux】系统引导修复
linux·运维·服务器