XiLaiTL大约 1 分钟

(By Deepseek)

在 VS Code 中安装 Remote - SSH 扩展

打开 VS Code,进入 Extensions(Ctrl+Shift+X),搜索 "Remote - SSH" 并安装。Remote - SSHopen in new window Remote - SSH: Editing Configuration Filesopen in new window Remote Exploreropen in new window

确保 Ubuntu 虚拟机已开启 SSH 服务

首先记得换源一下

  • 在 Ubuntu 终端运行:
    sudo apt install openssh-server -y
    sudo systemctl enable --now ssh
    
  • 检查 SSH 是否运行:
    sudo systemctl status ssh
    ctrl Z
    
    如果显示 active (running),说明 SSH 服务已启动 [2][3]。

获取 Ubuntu 虚拟机的 IP 地址

  • 在 Ubuntu 终端运行:
    ip a
    
    hostname -I
    
    找到类似 192.168.x.x 的 IP 地址。

配置 SSH 连接

  • Ctrl Shift P,输入 "Remote-SSH: Connect to Host...",选择 "Add New SSH Host"
  • 输入 SSH 命令格式:
    ssh username@ubuntu_vm_ip
    
    例如:
    ssh user@192.168.1.100
    
  • 选择保存到 ~/.ssh/config 文件,并输入密码(或配置 SSH 密钥免密登录)。

连接 Ubuntu 虚拟机

  • 再次按 F1,选择 "Remote-SSH: Connect to Host...",选择刚才添加的主机。
  • 输入 Ubuntu 用户的密码(如果未配置密钥),即可在 VS Code 中远程编辑文件 。

其他:修改主机配置

Change host file.

Host ecs-0001
    HostName xxx.xxx.xxx.xx
    User root
    Port 22

If failed, should login the host to edit /etc/ssh/sshd_config, setting AllowTcpForwarding yes. And restart the sshd in host.

sudo systemctl restart sshd

Then re-try the 'Remote - SSH : Connect to Host'.

上次编辑于:
贡献者: XiLaiTL