如何在新机器上设置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

相关推荐
ai小鬼头3 小时前
Ollama+OpenWeb最新版0.42+0.3.35一键安装教程,轻松搞定AI模型部署
后端·架构·github
李大玄8 小时前
Google浏览器拓展工具 "GU"->google Utils
前端·javascript·github
每天吃饭的羊8 小时前
github上部署自己的静态项目
github
qianmoQ9 小时前
GitHub 趋势日报 (2025年07月05日)
github
weixin_3077791310 小时前
批量OCR的GitHub项目
python·github·ocr
前端 贾公子12 小时前
monorepo + Turborepo 缓存
github
独立开阀者_FwtCoder13 小时前
放弃 JSON.parse(JSON.stringify()) 吧!试试现代深拷贝!
前端·javascript·github
网硕互联的小客服13 小时前
如何排查服务器中已经存在的后门程序?
运维·服务器·github
小妖66614 小时前
git branch -a 还有一些已经删除了的分支
git