【ssh】vscode 远程连接(本地虚拟机) Linux 服务器

本文档详述了如何使用Visual Studio Code (VSCode) 的Remote-SSH插件连接到本地Linux虚拟机或远程Linux服务器。首先在VSCode中安装Remote-SSH插件,然后配置SSH设置,包括显示登录终端选项。接着在Linux系统上安装并配置OpenSSH-Server,允许指定用户登录。最后,在VSCode中配置SSH连接信息,并进行连接操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

vscode 远程连接「本地 Linux 系统虚拟机」 或 「 Linux 服务器」详细教程

vscode 安装 Remote-SSH 并配置

  1. 首先打开 vscode,找到 Extensions,搜索 Remote,下载 Remote-Developoment 插件,会自动安装其他的 Remote 插件,其中会包含 Remote-SSH 插件:
    在这里插入图片描述

    插入:我这里把 Remote-SSH 的版本改到了 0.55.0,因为更新后的版本出现了莫名的 bug
    image

  2. 进入设置,搜索ssh,找到并选中拓展中的 Remote-SSH 中的 Show Login Terminal 选项,因为在连接的时候,终端会让你输入 yes 或者密码等:
    在这里插入图片描述
    在这里插入图片描述

  3. 接着,需要配置你的Linux服务器地址信息,按 CTRL+SHIFT+P,搜索ssh,找到 Open Configuration File 选项
    在这里插入图片描述

    插入:如何获取远程 IP 地址
    打开虚拟机终端,输入命令 ifconfig,下图红色框便是所需的 IP 地址:
    image

    接着输入自己的地址信息:
    (该配置文件路径一般是:C:\Users\lenovo\.ssh\config,lenovo 为 windows 用户名)
    image

= = = = = = = = = = = = = = = = = = = = = = 分割线:这部分是 Linux 系统的配置 = = = = = = = = = = = = = = = = = = = = = =
以下是 Linux 部分

Linux 安装 OpenSSH-Server 并配置

  • Ubuntu

    // 先卸载
    sudo apt-get remove openssh-server
    // 安装
    sudo apt-get install openssh-server
    
    // 重启ssh 服务
    sudo service ssh --full-restart
    // 自动启动
    sudo systemctl enable ssh
    
  • centos

    // 安装
    yum install -y openssl openssh-server
    // 重启 ssh 服务
    systemctl restart sshd.service
    // 自动启动
    systemctl enable sshd
    
  • 编辑配置文件

    sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup # 备份
    sudo vim /etc/ssh/sshd_config # 编辑
    

    配置文件中添加如下配置:

    Port 22
    UsePrivilegeSeparation no
    PasswordAuthentication yes
    PermitRootLogin yes
    AllowUsers hhh # 这里的 "hhh" 改成你自己的登陆用户名
    # ----------------- 以下提前留出公钥配置(可选)-----------------------
    RSAAuthentication yes
    PubKeyAUthentication yes
    

    端口可选,默认为 22,对应前面配置文件中的端口号即可。
    保存后,重启 ssh 服务器,重启服务:sudo service ssh --full-restart

以上 Linux 部分结束!

= = = = = = = = = = = = = = = = = = = = = = 分割线:以下部分配置 vsode = = = = = = = = = = = = = = = = = = = = = = = = =

编写 vscode 的 ssh 配置文件

再来配置vscode:

  1. 设置配置文件:
    在这里插入图片描述
    加入下面两行:

    "remote.SSH.remotePlatform":{
        "ubuntu18.04": "linux"  // 远程连接时,自动选择linux系统,注意和上面的"host"匹配
    },
    "remote.SSH.useLocalServer":true,  // 使用本地服务器
    

    在这里插入图片描述

  2. 进行 ssh 远程连接
    (1)vscode 第一次 ssh 远程连接,需要按下 ctrl+shift+p,输入 ssh,如图操作进行连接:
    在这里插入图片描述
    (2)后面可以在管理栏进行连接:
    在这里插入图片描述

= = = = = = = = = = = = = = = = = = = = = = The End = = = = = = = = = = = = = = = = = = = = = =

### 回答1: 在 TURBO C 2.0 中,您可以使用 biosdisk() 函数来格式化软盘。 下面是一段代码示例: ``` #include <stdio.h> #include <dos.h> int main() { // 定义扇区的大小 unsigned int sector_size[3] = {512, 512, 1024}; // 定义填充字节 unsigned char fill_char[3] = {0xF6, 0xF6, 0x48}; // 格式化磁道 70 面 0 的前三个扇区 for (int i = 0; i < 3; i++) { int result = biosdisk(2, 0, 70, 0, i + 1, 1, sector_size[i], fill_char[i]); if (result != 0) { printf("格式化扇区 %d 失败,返回码: %d\n", i + 1, result); } } return 0; } ``` 请注意,在使用 biosdisk() 函数之前,需要包含 dos.h 头文件。 希望这能帮到您! ### 回答2: 使用TURBO C 2.0语言,可以通过以下代码格式化软盘的70磁道0面,并分别格式化3个扇区,大小分别为512字节、512字节和1024字节。其中,前两个扇区使用F6填充,第三个扇区使用48填充。 ```c #include<stdlib.h> #include<stdio.h> #include<dos.h> void formatFloppyDisk(){ union REGS regs; regs.h.ah = 0x0;// To format a floppy disk, we set AH=0 regs.h.dl = 0;// Drive number (0=A, 1=B, etc.) regs.x.cx = 0;// Track number to format regs.h.dh = 0;// Head number regs.h.al = 0;// Sector size (0=default, 1=512 bytes, 2=1024 bytes, 3=2048 bytes etc.) int FILL_BYTE = 0;// The byte value to fill the sectors with during formatting int NUM_SECTORS = 3;// Number of sectors to format // To format 70th track 0th head regs.x.ax = 0x1301; // 0x13 = Reset disk system, 01H = Reset only specified drive int86(0x13, &regs, &regs); // BIOS interrupt to reset disk system for (int i=0; i<NUM_SECTORS; i++){ regs.x.ax = 0x3101; // 0x31 = Write Format, 01H = Format only current track regs.x.bx = 0x0001; // 0x00 = Drive A:, 01H = Head 1, 0 = Generate ID Field depending on the disk in the drive 1 = Keep the ID Field all zeros regs.x.cx = 0x0170; // Track number=70(0-79 range) regs.h.dh = 0x00; // Head number=0 or 1 regs.h.al = 0x02; // Control byte=always zero regs.x.dx = i+1; // Sector number starting from 1 regs.x.si = 0x0000; // segment and offset of read/write buffer regs.x.di = 0x0000; // segment and offset of result if(i == 2){ FILL_BYTE = 0x48; // Fill the third sector with 48 regs.x.ax = 0x3102; // 0x31 = Write Format, 02H = Format sequential tracks immediately following the one being formatted }else{ FILL_BYTE = 0xF6; // Fill the first two sectors with F6 } regs.h.ah = FILL_BYTE; // Fill the sector with specified byte int86(0x13, &regs, &regs); // BIOS interrupt to format the specified sector } } int main(){ formatFloppyDisk(); return 0; } ``` 上述代码使用了INT 0x13,即BIOS中断服务例程,来执行软盘格式化操作。通过设置寄存器的不同参数,可以指定要格式化的磁道、面、扇区大小和填充字节。在这个例子中,我们格式化了软盘70磁道0面的3个扇区,前两个扇区使用F6填充,第三个扇区使用48填充。
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值