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

问题

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

原因

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

解决方法

使用 SSH 密钥认证

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

  1. 在远程服务器生成 SSH 密钥(如果没有的话)
ssh-keygen -t ed25519 -C "[email protected]"

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

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

成功的话会看到类似:

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

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

git remote set-url origin [email protected]:your_username/your_repo.git
  1. 重新推送代码:
git push -u origin main

至此,推送成功!!!

你可能感兴趣的:(Git,vscode,linux,github)