将文件推送到远程时权限被拒绝

Sha*_*raj 3 git ssh github git-bash

我之前使用 git bash 作为本地存储库。
我已连接到 GitHub 帐户,并且总是毫无问题地推送我的文件。
后来,我卸载了 bash 并使用新用户和电子邮件重新安装。现在,当我尝试将文件推送到远程时,出现错误:

 Permission to SyedMiraj/SpringSecurityWithTicketBooking.git denied to biid-sua.
 unable to access 'https://github.com/SyedMiraj/SpringSecurityWithTicketBooking.git/': The requested URL returned error: 403
Run Code Online (Sandbox Code Playgroud)

我尝试创建一个新的 SSH 密钥并将其添加到远程存储库中。
但问题仍然存在,说实话我无法将任何东西推送到我的遥控器上。
我的两个 GitHub 帐户是 biid-sua 和 smiraj。

您建议如何恢复 GitHub 推送?

Von*_*onC 5

这里有几点:

  • 用于提交的用户和电子邮件与用于身份验证的远程存储库(此处托管在 GitHub 上)无关
  • 使用https URL推送到 GitHub 时根本使用SSH 密钥(旧的或新的)。 如果它使用您的第一个帐户,这是因为 git 凭据助手已缓存您的.
    biid-suabiid-suagithub.com

您可以确认并删除该条目(在 MacWindows 上)。下次推送时,系统将提示您输入新的用户名/密码。

或者您可以切换到 SSH URL:

cd /path/to/my/local/repo
git remote set-url origin g2:SyedMiraj/SpringSecurityWithTicketBooking.git
Run Code Online (Sandbox Code Playgroud)

然后确保您~/.ssh/config定义了g2条目并引用了正确的键(正如我在这里解释的那样

#Account one
Host g1
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile /c/Users/yourname/.ssh/id_rsa_biid-sua
    User git

#Account two
Host g2
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile /c/Users/yourname/.ssh/id_rsa_smiraj
    User git
Run Code Online (Sandbox Code Playgroud)

假设您已在 HOME 中命名 SSH 密钥:

  • .ssh/id_rsa_biid-sua.ssh/id_rsa_biid-sua.pub
  • .ssh/id_rsa_smiraj.ssh/id_rsa_smiraj.pub