90 lines
2.5 KiB
Markdown
90 lines
2.5 KiB
Markdown
# 1. vscode使用ssh链接虚拟机服务器
|
||
|
||
# 2. 前言
|
||
|
||
   在vscode使用ssh工具远程登录虚拟机服务器进行代码编辑。
|
||
|
||
| 内容 | 时间 | 作者 | 备注 |
|
||
|----|----|----|----|
|
||
| 首版 | 2024-2-26 | xjz | - |
|
||
|
||
## 2.1. Windows系统
|
||
|
||
* 安装ssh
|
||
|
||
   直接安装git工具即可支持ssh
|
||
|
||
安装完后确认:
|
||
```
|
||
xiaojiazhu@ubuntu:~/project/rkipc/battery/ipc-rk1106/ipc-sdk/cmake-shell$ 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]
|
||
```
|
||
|
||
* vscode安装ssh插件
|
||
|
||
   使用 Remote - SSH 插件
|
||
|
||
* ssh密钥配置
|
||
|
||
1. Windows生成密钥;
|
||
2. 把xxx.pub文件内容拷贝到虚拟机的ssh目录下的authorized_keys文件;
|
||
此处是:
|
||
|
||
```
|
||
xiaojiazhu@ubuntu:~/project/.ssh$ pwd
|
||
/home/xiaojiazhu/project/.ssh
|
||
xiaojiazhu@ubuntu:~/project/.ssh$ ls
|
||
authorized_keys id_rsa id_rsa.pub
|
||
```
|
||
|
||
这样设置后,每次登录ssh无需手动输入密码;
|
||
|
||
3. 在Windows远程登录虚拟机:
|
||
|
||
参考命令:ssh xiaojiazhu@192.168.1.29
|
||
|
||
```
|
||
PS C:\Users\xjz\.ssh> ssh xiaojiazhu@192.168.1.29
|
||
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-94-generic x86_64)
|
||
|
||
* Documentation: https://help.ubuntu.com
|
||
* Management: https://landscape.canonical.com
|
||
* Support: https://ubuntu.com/advantage
|
||
|
||
Expanded Security Maintenance for Applications is not enabled.
|
||
|
||
75 updates can be applied immediately.
|
||
To see these additional updates run: apt list --upgradable
|
||
|
||
9 additional security updates can be applied with ESM Apps.
|
||
Learn more about enabling ESM Apps service at https://ubuntu.com/esm
|
||
|
||
New release '22.04.3 LTS' available.
|
||
Run 'do-release-upgrade' to upgrade to it.
|
||
|
||
Your Hardware Enablement Stack (HWE) is supported until April 2025.
|
||
*** System restart required ***
|
||
Last login: Sun Feb 25 17:20:04 2024 from 192.168.1.29
|
||
xiaojiazhu@ubuntu:~$
|
||
```
|
||
## 2.2. vscode设置
|
||
|
||
配置文件参考
|
||
|
||
```
|
||
Host dgiot // 自定义的主机名
|
||
HostName 192.168.1.29 // 远端的IP地址
|
||
User xiaojiazhu 用户名
|
||
Port 22
|
||
IdentityFile "C:\Users\xjz\.ssh\id_ed25519" // 本端的私钥文件路径
|
||
ForwardAgent yes // 忽略
|
||
```
|
||
|
||
多个远端IP复制即可。
|