GitHub 命令行 git push 提交代码时报错:The requested URL returned error: 403

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/winteroak/article/details/101059347

问题

使用 git 的命令行向 GitHub 提交的时候,报错:

[root@toolsqa QaTools]# git remote add origin https://github.com/toolsqacn/qatoolsweb.git
[root@toolsqa QaTools]# git push -u origin master
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/toolsqacn/qatoolsweb.git/info/refs

fatal: HTTP request failed

解决办法

在项目根目录中修改 .git 目录下的config 配置

  1. 进入 .git 目录
cd .git
# 执行后,可以用 ls 命令查看一下,会有一个 config 文件
  1. 修改 config 文件

找到 [remote “origin”] 节点下的 url 项,

url =https://github.com/toolsqacn/qatoolsweb.git

改成

url = ssh://[email protected]/toolsqacn/qatoolsweb.git

用户名( toolsqacn )和 仓库名(qatoolsweb.git) 修改成自己的 用户名 和 仓库名

  1. 重新提交
git push origin master

当有冲突要强制提交时使用

 git push --force origin master

本地 SSH Key 生成与设置

SSH Key 生成命令 ·ssh-keygen -t rsa -C‘

[root@toolsqa .ssh]# ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
7e:e8:79:ec:d1:e6:71:b1:59:50:45:ac:2d:b7:84:92 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|               o=|
|               ..|
|            . oo |
|           E .ooo|
|        S   . ooo|
|       . . .   * |
|        o.o + +  |
[core]
|       . oo+ o   |
|        oo. .    |
+-----------------+
[root@toolsqa .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[root@toolsqa .ssh]# cat *pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyZtF4mrpmsTm64uwlmAh4Ov+I5hPH8ECdkBj/W1b4yBKgpIPJQDmePYWVqpd2dJ4YLPiFDhtC37+TNyHWsT/ssEDll406sFQXhr235Hqr61+QNhR1BFB4fePRIf42T5fqiPR1sbDrvx+qWM3xka5nieEHQbNK/vkcXGt2KiFpbbXtbQEbxFDFRanbitcZ9+lbIXvnFT73hCoEaaFd5hNduKd+c9IY2SiLMySU76UuREjLbemY3vto3wSJEYVmeItsuwAolJSZaz9UUaYxzezmDs85rWRWr4AvM8zzRzswAMz+KRIbcVe+EXu1XiGW+5WebFZ05e31IFiqjfdH/d8Sw== [email protected]

GitHub SSH Key 设置

设置地址为:https://github.com/settings/ssh/new
自定义 SSH Key 名称和填入本地生成的Key
界面如图:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/winteroak/article/details/101059347
今日推荐