VSCode安装SSH远程开发插件

mac2024-05-13  27

VSCode安装SSH远程开发插件

vscode

步骤概述

1、ssh秘钥生成 与授权

目标是生成一对公私钥,公钥注册在远程服务器authority,使用本地私钥登录远程服务器

2、SSH客户端安装

确保当前平台已经安装ssh客户端

3、vscode插件安装

安装vscode remote插件

4、vscode 免密SSH登录

主要是配置文件,和远程vscode server

使用平台:

本地PC:win10 安装VScode,git bash

远程虚拟机:ubuntu16.04 已安装vim

SSH秘钥生成与添加授权

目标是生成SSH秘钥对,其中id_xxx.pub为公钥,需要部署到远程服务器

id_xxx id_xxx.pub

SSH秘钥最常见的是RSA,最佳方案是 ED25519 安全性更好,计算量更低。

推荐使用 ED25519方案,如果远程ssh server版本太老,那么请使用RSA

选择一:ssh-keygen生成ED25519 ssh-pair

ssh-keygen -t ed25519 -C "vscode-use"

选择二:ssh-keygen生成RSA ssh-pair

ssh-keygen -t rsa -C"vscode-use"

生成过程中 Enter passphrase (empty for no passphrase): 如果不要密码保护可以直接enter

复制秘钥文件的值

秘钥文件默认保存文件地址为当前用户(abc)的.ssh目录下 例如 c:/Users/abc/.ssh/

cat id_ed25519.pub |clip
将SSH pub中的值 加入远程服务器的 authorized_keys,以root用户为例
vim /root/.ssh/authorized_keys
插入公钥值,类似如下
ssh-ed25519 AAAAC3Nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+Imv vscode-use

至此,已经生成SSH秘钥对,并添加公钥到远程服务器

SSH客户端安装

打开git bash 或者 powershell 输入如下命令

ssh usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] destination [command]

说明已经安装SSH client

如果显示没有安装,请参考 微软 https://docs.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_install_firstuse

VSCode插件安装

Remote Development 插件安装
选择vscode左边栏中的Extension,搜索 remote

vscode会顺便安装 SSH ,SSH Exploer等功能插件

买一送五

VSCode 免密SSH登录

进入SSH Exploer

在如上图的弹窗中 进入 Setting

其中 .ssh\config文件设置如下

Host 本地VM HostName 192.168.1.2 User root IdentityFile C:\xxx\.ssh\id_ed25519

其中 注意两点 HostName 为远程域名或者IP地址

如果配置没有问题的话,接下来就可以 SSH Exploer里面选择已经配置好的远程机器

如下图

欢迎关注 GoCoder公众号 微信号:gocoder8 扫一扫

参考文档

https://code.visualstudio.com/docs/remote/ssh#_getting-started

最新回复(0)