如何在新机器上设置github完成内容git push

发布于:2025-07-09 ⋅ 阅读:(11) ⋅ 点赞:(0)

如果你在一台新的机器上git pull 仓库,完成修改,然后git push,会发现下面错误:

Username for 'https://github.com': xiaomaolv
Password for 'https://xiaomaolvgithub.com': 
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/xiaomaolv/'

这是因为你第一次在这台机器上操作,需要设置.

方案1 ssh

首先在本地机器生成ssh,如果已经有可以掠过:

 $ ssh-keygen -t rsa -C "xiaomaolv@xjblll-tech.comm"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/xiaomaolv/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/xiaomaolv/.ssh/id_rsa
Your public key has been saved in /home/xiaomaolv/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:onw16/MR30zP4u+dUmxKdnvtzLZ5jdU5iN4Qb4dIaj4 xiaomaolv@xjblll-tech.comm
The key's randomart image is:
+---[RSA 3072]----+
|                 |
|                 |
|                 |
|           o     |
|      . S + = = o|
|   . . o = * @ @o|
|    o . + o B XoB|
|     . ..E o =.=X|
|        .oo   oO@|
+----[SHA256]-----+

然后copy ssh-rsa 到github网页中的SSH and GPG keys中

cat /home/xiaomaolv/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDLu5oKyIQjFXv4JPNZHlStLLcN+5uGR7yaacuRXJ4/uust0z6AXAAm/8X9pU3CMBbFbkgNSsBngmFJcXUMOZTrTIjcIMFAjbZwO7/gdY9XoiiKG+0zqKeCTzqgJsBBvaZQwihil9r3gLahgJMFzZhS457Zwu35xCwD7CKT5BBxD96oTCDgn88rCFLRwzQ7bA8fyLvKvKkJLbRDqbfLv3XkbsyAfJcWtTgLbfGe76pxiPeICYeIBrJDsVG0TwfThS+vlF4Dq8rNL3k6QAD59TRYsqlqY5LobeQy1sSkPFK4Xa+PAgeVydx4O3M91/V46HF3oCI2MYi505HnxQ19KykqEkShVzuaWXamGP3QMU4ZJzww88W84qkYvNW4yO/PWafoQbgZj3qVjXZkp+2WBd112uz+jwhzB/lz5i/uMyo8TKCVy3lYubiIFhswVhn6NicsMbMKAn+qWbebxquL+3eEWt14s4/lMIXU5xH6KVNlJEGH/0EkBrylVPZA0/UTyb8= xiaomaolv@xjblll-tech.comm

打开github网页,并添加:
在这里插入图片描述

本地执行测试

如果出现下面信息,则说明成功了。

$ ssh -T git@github.com
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
Hi ! You've successfully authenticated, but GitHub does not provide shell access

切换认证方式:

# 切换到 SSH
git remote set-url origin git@github.com:EnflameTechnology/FFmpeg-GCU.git

git push

$ git push
Enumerating objects: 17, done.
Counting objects: 100% (17/17), done.
Delta compression using up to 16 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 947 bytes | 947.00 KiB/s, done.
Total 9 (delta 7), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (7/7), completed with 7 local objects.
To github.com:EnflameTechnology/FFmpeg-GCU.git
   3ef21d7..b68a39c  main -> main

note: 如果在这个阶段还是出现permission not allowed ,那么就要去找github 仓库管理员要权限了。

http方式

除了上面提供的ssh方式,github还提供了第二种方式http方式
执行的命令如下,核心是如何获取TOKEN,

# 或切换到 PAT
git remote set-url origin https://<TOKEN>@github.com/EnflameTechnology/FFmpeg-GCU.git

其中是:
GitHub → Settings → Developer settings → Personal access tokens
TOKEN同时会发邮件到邮箱
在这里插入图片描述

总结:

两种方式git push


网站公告

今日签到

点亮在社区的每一天
去签到