当前位置:网站首页>VSCode使用 - Remote-SSH 配置说明
VSCode使用 - Remote-SSH 配置说明
2022-06-26 16:51:00 【jackailson】
By: Ailson Jack
Date: 2022.06.17
个人博客:http://www.only2fire.com/
本文在我博客的地址是:http://www.only2fire.com/archives/147.html,排版更好,便于学习,也可以去我博客逛逛,兴许有你想要的内容呢。
我的环境说明:
- 本地环境:Windows 11
- 远端环境:Ubuntu 22.04 LTS(运行在虚拟机中)
Remote-SSH简介
Remote-SSH是一个VSCode的插件,Remote-SSH可以让你使用任何带有SSH服务的远端机器作为你的开发环境。这可以大大简化各种情况下的开发和故障排除。使用了Remote-SSH插件之后,你可以:
- 在您部署的同一操作系统上进行开发,或者使用比本地计算机更大、更快或更专业的硬件。
- 在不同的远程开发环境之间快速切换,并安全地进行更新,而无需担心影响本地计算机。
- 从多台计算机或多个位置访问现有开发环境。
- 调试在其他地方(如客户站点或云中)运行的应用程序。
Remote-SSH安装和环境准备
首先安装VSCode,然后在扩展中搜索"Remote",安装搜索到的"Remote-SSH"和"Remote-Containers","Remote-SSH: Editing Configuration"插件会在安装"Remote-SSH"插件时自动安装:

确保远端环境(Ubuntu 22.04 LTS)中SSH服务可用。
确保本地环境中支持SSH,这个可以通过安装Git来获取SSH功能。
SSH密钥配置
本节将在Windows上生成SSH密钥,然后部署到Ubuntu 22.04 LTS系统中,这样每次重启VSCode之后,使用Remote-SSH访问Ubuntu 22.04 LTS系统中的文件时,不需要手动输入密码了。
生成SSH密钥文件
在Windows系统上执行下述命令生成SSH密钥:
ssh-keygen
输入上述命令之后,遇到等待时,直接按ENTER键保持默认,需要敲击3次ENTER键,然后就会在 C:\Users\AilsonJack\.ssh 目录中产生SSH密钥文件:id_rsa 和 id_rsa.pub。
部署密钥文件到Ubuntu
首先,确保当前用户的用户目录下是否存在 .ssh 目录(我这里的完整路径为:/home/ailsonjack/.ssh ),执行下述命令,查看输出信息中是否有 .ssh 目录:
ls -al ~
如果不存在 .ssh 目录,那么执行下述命令进行创建:
mkdir ~/.ssh
通过FTP,SFTP,samba等方式将生成的 id_rsa.pub 文件传输到Ubuntu 22.04 LTS系统中的 /home/ailsonjack/.ssh 目录中。
生成 authorized_keys 文件
进入 /home/ailsonjack/.ssh 目录,然后使用下述命令,生成 authorized_keys 文件:
cat id_rsa.pub > authorized_keys
Remote-SSH配置
下面将讲述一下Remote-SSH的一些配置,完成Remote-SSH的配置之后,就可以通过Remote-SSH访问Ubuntu 22.04 LTS系统中的文件或者文件夹,就像在本地电脑开发一样。
打开VSCode,然后点击左侧的 “远程资源管理器” 图标,接着点击右上角的小齿轮(设置):

在弹出来的窗口中,选择第一项,打开 config 文件,然后填写配置信息:


配置信息的文字内容如下:
Host Ubuntu22.04
HostName 192.168.1.5
User ailsonjack
IdentityFile C:\Users\AilsonJack\.ssh\id_rsa
上述配置信息的注释如下:
Host <远程主机名称>
HostName <远程主机IP>
User <用户名>
IdentityFile <本机SSH私钥路径>
在完成上述配置之后,进入 “远程资源管理器” 选项,右键点击主机名,然后选择“Connect to Host in Current Window”或者“Connect to Host in New Window”:

如果连接成功,左下角则会显示当前已连接的主机名:

点击“打开文件夹”可以打开Ubuntu系统中的文件夹,我这里打开了Ubuntu系统中的Linux内核文件夹,此时我们就可以在Windows系统中,利用VSCode的Remote-SSH插件阅读Ubuntu系统中的Linux内核源码,是不是很酷:

安装插件到远端系统
当我们完成对Remote-SSH的配置之后,VSCode 支持在 远程服务器 安装插件。此时我们可以根据自己的需求安装插件到远端系统,也可以将本地的插件一键全部安装到远端系统:

点击上图中红色方框的图标,就可以将本地的插件一键全部安装到远端系统。
欢迎关注博主的公众号呀(微信搜索公众号:嵌入式那些事),可以扫描下面的公众号二维码(为防止公众号二维码被CSDN处理掉,二维码图片周围加了些东西,如果公众号图片真被CSDN处理了,也可以直接访问我的个人博客文章获取公众号二维码图片):

如果文中有什么问题欢迎指正,毕竟博主的水平有限。
如果这篇文章对你有帮助,记得点赞和关注博主就行了^_^。
排版更好的内容见我博客的地址:http://www.only2fire.com/archives/147.html
注:转载请注明出处,谢谢!^_^
边栏推荐
- Introduction to minimal API
- vue--vuerouter缓存路由组件
- Stm32f103c8t6 realize breathing lamp code
- 链游系统开发技术方案设计丨NFT链游系统开发流程及源码
- Junit单元测试
- LeetCode Algorithm 24. Exchange the nodes in the linked list in pairs
- Demonstrate to Xiaobai the case of sub database and sub table
- Implementation of MySQL master-slave architecture
- Decentralized NFT transaction protocol will defeat opensea
- [latex bearer] use tables in \title (error \begin doesn't match its definition.)
猜你喜欢

20:第三章:开发通行证服务:3:在程序中,打通redis服务器;(仅仅是打通redis服务器,不涉及具体的业务开发)

数字藏品与NFT到底有何区别

Here comes the hero League full skin Downloader

Constructors and Destructors

Byte interview: two array interview questions, please accept
![[C language] static modifies local variables](/img/bf/9084d2e924c3e1e244568562a83d74.jpg)
[C language] static modifies local variables

并发之Synchronized说明

Gui+sqlserver examination system

ACL 2022 | zero sample multilingual extracted text summarization based on neural label search

She said she was tired! So tired! I want to change my career
随机推荐
Experience in hierarchical debugging of boards and cards
Leetcode topic [array] -283- move zero
When I was in the library, I thought of the yuan sharing mode
Microservice architecture practice: business management background and SSO design: SSO design
去中心化NFT交易协议将击败OpenSea
Find all primes less than or equal to Lim, store them in AA array, and return the number of primes
Byte interview: two array interview questions, please accept
Use FST JSON to automatically generate faster JSON serialization methods
Environment setup mongodb
Inspirational. In one year, from Xiaobai to entering the core Department of Alibaba, his counter attack
Use the array to calculate the average of N numbers, and output the numbers greater than the average
The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
Discover K8E: minimalist kubernetes distribution
数字藏品与NFT到底有何区别
Alibaba's "high concurrency" tutorial "basic + actual combat + source code + interview + Architecture" is a god class
Interpretation of new plug-ins | how to enhance authentication capability with forward auth
【推荐系统学习】推荐系统架构
Greenplum database fault analysis - semop (id=2000421076, num=11) failed: invalid argument
What is the preferential account opening policy of securities companies now? Is it safe to open an account online now?
Gui+sqlserver examination system