vscode连接的linux服务器,上传项目至github

问题

已将项目整个文件夹拷贝到克隆下来的文件夹中,并添加了所有文件,并修改了commit -m,使用git push -u origin main提交的时候会出现vscode请求登录github,确定之后需要等待很久,也无果

原因

由于 远程服务器无法访问 GitHub 网页认证服务,也就是 GitHub 的 OAuth 网页流程(VS Code 的 GUI 登录)在你的远程服务器上不适用或者被阻断。

解决方法

使用 SSH 密钥认证

这是最稳定、适合远程服务器的方法

步骤:

  1. 在远程服务器生成 SSH 密钥(如果没有的话)
bash 复制代码
ssh-keygen -t ed25519 -C "your_email@example.com"

按提示一路回车即可,生成的密钥一般保存在 ~/.ssh/id_ed25519 和 id_ed25519.pub。

  1. 查看公钥内容(复制用):
bash 复制代码
cat ~/.ssh/id_ed25519.pub
  1. 将公钥添加到 GitHub:
  • 登录 GitHub;
  • 进入 Settings > SSH and GPG keys;
  • 点击 "New SSH key";
  • 填写标题,粘贴上面复制的公钥。
  1. 测试 SSH 是否配置成功:
bash 复制代码
ssh -T git@github.com

成功的话会看到类似:

bash 复制代码
Hi your_username! You've successfully authenticated, but GitHub does not provide shell access.
  1. 确保 Git 使用 SSH 地址作为远程仓库地址:
    检查:
bash 复制代码
git remote -v

如果显示的是 https://github.com/...,你需要改为 SSH 形式:

bash 复制代码
git remote set-url origin git@github.com:your_username/your_repo.git
  1. 重新推送代码:
bash 复制代码
git push -u origin main

至此,推送成功!!!

相关推荐
砖厂小工3 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
程序员鱼皮4 小时前
又一个新项目完结,我要出海了!
ai·github·开源项目
徐小夕4 小时前
pxcharts-vue:一款专为 Vue3 打造的开源多维表格解决方案
前端·vue.js·github
Moment5 小时前
想要长期陪伴你的助理?先从部署一个 OpenClaw 开始 😍😍😍
前端·后端·github
我叫黑大帅5 小时前
前端如何利用 GitHub Actions 自动构建并发布到 GitHub Pages?
前端·面试·github
HelloGitHub7 小时前
这个年轻的开源项目,想让每个人都能拥有自己的专业级 AI 智能体
开源·github·agent
刘发财13 小时前
弃用html2pdf.js,这个html转pdf方案能力是它的几十倍
前端·javascript·github
sunny86521 小时前
Claude Code 跨会话上下文恢复:从 8 次纠正到 0 次的工程实践
人工智能·开源·github
ZengLiangYi1 天前
Git Tag + Semver + CI/CD:从打标签到自动发布的完整实践
github