我有一个新系统(MacBook Pro),想要对其进行设置,以便它可以直接推送到我在 GitHub 上的远程存储库。我遵循的步骤是:
- 使用命令
ssh-keygen -t rsa
生成 ssh key 。 - 将
id_rsa.pub
中的内容复制到我的 Github 帐户的 SSH key 区域。 - 在 GitHub 上创建了存储库。
- 使用 git remote set-url origin https://github.com/username/repo.git 将存储库 URL (https) 复制到我现有的本地项目中。
- 使用
git pull origin master
进行 pull (没有错误)。 - 使用
git push origin master
推送新更改时,出现以下错误。
remote: Permission to UserName/repo-name.git denied to name.
fatal: unable to access 'https://github.com/UserName/repo-name.git/': The requested URL returned error: 403
问题:
1. 为什么即使将 SSH key 添加到 Github 后,我仍会收到权限被拒绝错误?添加 SSH key 后,GitHub 不应该将我的系统视为可信设备吗?
2. 如何将我的系统添加为受信任设备,以免出现权限被拒绝错误?
最佳答案
- Why am I getting the permissions denied error even after adding the SSH key to Github?
因为您使用的是 SSH key ,这与 HTTPS 身份验证(基于用户名/密码)无关
How do I add my system as a trusted device so that I don't get the permissions denied error?
设置正确的 SSH URL
git remote set-url origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="41262835012628352934236f222e2c" rel="noreferrer noopener nofollow">[email protected]</a>:USERNAME/REPOSITORY.git
^^^^^^^
区分大小写,用户名必须是您的存储库所在的 GitHub 用户名。
它与 git config user.name/user.email 无关(根本不用于身份验证,仅用于提交作者身份)
或者您保留当前的 HTTPS URL,但检查凭证管理器是否缓存了错误的凭证:
git config credential.helper
例如,for a manager one ,您可以拒绝与 github.com
关联的旧凭证/填写新凭证(GitHub 用户名/密码)。
关于git - 即使将公共(public) ssh key 添加到 Git Hub 后,也无法将更改从本地系统推送到源系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58122460/