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界面进行提交代码了

相关推荐
王亭_66611 分钟前
VSCode集成deepseek使用介绍(Visual Studio Code)
ide·vscode·编辑器·deepseek·openrouter
slomay3 小时前
项目汇报PPT转视频制作 | 有字幕和配音版
经验分享·github
爱健身的小范3 小时前
记录一下VScode可以使用nvcc编译,但VS不行的解决方案
ide·vscode·编辑器
翻滚吧键盘3 小时前
vscode复制到下一行
ide·vscode·编辑器
人工干智能3 小时前
科普:“git“与“github“
git·github
柯腾啊5 小时前
VSCode 中使用 Snippets 设置常用代码块
开发语言·前端·javascript·ide·vscode·编辑器·代码片段
perseverance525 小时前
VSCode自定义快捷键和添加自定义快捷键按键到状态栏
vscode·vscode快捷键配置
davenian6 小时前
< OS 有关 > Ubuntu 24 SSH 服务器更换端口 in jp/us VPSs
linux·ubuntu·ssh
张海森-16882011 小时前
MobaXterm通过ssh远程连接Ubuntu的方法
ubuntu·ssh
今天吃了嘛o15 小时前
vscode将文件中行尾默认CRLF改为LF
vscode·编辑器