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

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

bash 复制代码
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,如果已经有可以掠过:

bash 复制代码
 $ 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中

bash 复制代码
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网页,并添加:

本地执行测试

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

bash 复制代码
$ 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

切换认证方式:

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

git push

bash 复制代码
$ 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,

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

其中是:

GitHub → Settings → Developer settings → Personal access tokens

TOKEN同时会发邮件到邮箱

总结:

两种方式git push

相关推荐
阿里嘎多学长5 小时前
2026-01-11 GitHub 热点项目精选
开发语言·程序员·github·代码托管
三两肉5 小时前
HTTPS ECDHE 握手全解析
网络协议·https·github·rsa·echde
啊湘5 小时前
vscode 使用 github (适用CURSOR等使用)
ide·vscode·github·cursor·mcp
l1t6 小时前
利用DeepSeek辅助拉取GitHub存储库目录跳过特定文件方法
人工智能·github·deepseek
Hilaku6 小时前
我用 Gemini 3 Pro 手搓了一个并发邮件群发神器(附源码)
前端·javascript·github
番茄灭世神8 小时前
Git入门使用学习
git·gitee·软件工程·计算机专业入门
逛逛GitHub8 小时前
GitHub 上 2300 人 Star 的 Claude Code 可视化工作流编辑器。
github
这儿有一堆花9 小时前
MusicFree:开源多平台聚合音乐软件
开源·github
南_山无梅落9 小时前
团队协作高频Git实用手册(项目实战版)
git·团队开发