VScode通过ssh连接github

通过ssh连接github

1.生成公钥和私钥

首先选择一个文件夹,右击 git bash here,在命令行输入命令,按下三次回车生成一个**.ssh文件夹**,一般在用户的user根目录下,文件夹中包括名为id_rsa的私钥文件和一个名为id_rsa.pub的公钥文件

bash 复制代码
ssh-keygen -t rsa -C "邮箱地址"//按下三次回车,生成公钥和私钥两个文件
# 或者
ssh-keygen -t rsa

2.设置config文件

找到.ssh文件夹后,在里面新建一个名为config的文件,不需要后缀名,然后在里面写入(不要忘记保存):

bash 复制代码
Host github.com
HostName ssh.github.com  
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

测试是否可以连接上GitHub

bash 复制代码
 ssh -T git@github.com

3.配置ssh免密登录

4.远程仓库初始化

进入vscode工作区,选中需要添加到仓库里的文件夹,右击终端打开,在终端里输入以下命令:

bash 复制代码
git init//仓库初始化
git add README.md//添加readme.md文件
git commit -m "first commit//提交
git branch -M main//构建分支
git remote add origin git@github.com:zhouwenbin888/ceshi.git//连接到远程仓库
git push -u origin main//推送

进行一次命令行提交代码之后,vscode会自动通过ssh连接到远程仓库,之后推送代码就可以使用vscode界面进行提交代码了

相关推荐
feasibility.6 小时前
SSH Agent Forwarding 与 tmux 排障笔记
linux·运维·服务器·经验分享·笔记·ssh
猿儿本无心8 小时前
仿VSCode做一个程序员快速装机工具
ide·vscode·编辑器
逛逛GitHub9 小时前
7 个最近 GitHub 上火火火的开源项目,推荐一哈。
github
__雨夜星辰__9 小时前
什么是 Git 与 Git※hub(※Git※hub加※速访※问教程)
git·github
子夜江寒9 小时前
GitHub入门协作
github
山川行10 小时前
关于《项目C语言》专栏的总结
c语言·开发语言·数据结构·vscode·python·算法·visual studio code
呆呆敲代码的小Y10 小时前
UnityMCP+Claude+VSCode,构建最强AI游戏开发环境
人工智能·vscode·游戏·unity·游戏引擎·u3d·mcp
逛逛GitHub10 小时前
一个运维人写了 12 年的开源项目,Star 刚刚破了 3 万。
github
daguanren11 小时前
LMRing 实测榜:GPT-5.4 登顶?Claude 4.6 还能打吗?
github·aigc
CoovallyAIHub11 小时前
Claude Code Review:多 Agent 自动审查 PR,代码产出翻倍后谁来把关?
算法·架构·github