利用vscode远程连接服务器,配置免密连接(亲测)

  1. 在vscode扩展搜索并安装远程ssh连接插件
    Remote-SSH 或者 Remote Development

  2. 在远程连接中打开配置文件
    这里要选择后续免密登录生成密钥文件下的config文件,当然默认都是选择第一个
    image.png
    config里面的内容就是你ssh连接的ip,端口号等
    创建ssh连接命令(p为端口号)

    1
    ssh usr@111.111.111.111 -p 123
  3. 免密登录设置
    打开cmd,输入

    1
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

    -t 指定密钥类型,默认即 rsa ,可以省略
    -C 设置注释文字,比如你的邮箱,可以省略
    回车跳过,会在默认文件夹,也就是第二步骤中的config文件夹中生成私钥文件 id_rsa 和公钥文件 id_rsa.pub
    注意,这里的公钥文件id_rsa.pub可以用于多个ssh链接,即一对多

  4. 配置服务器端

  • 进入服务器的ssh文件夹,如果是Linux系统,一般是/home/usrname/.ssh
  • 打开authorized_keys文件,如果没有就新建一个
  • 将第三步中生成的公钥id_rsa.pub中的内容复制到authorized_keys文件中
  • 完成免密设置

vscode 远程服务器调试选择其他id的显卡

在运行的配置中的env添加配置

“CUDA_VISIBLE_DEVICES”: “1”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceRoot}",
"env": {"PYTHONPATH":"${workspaceRoot}",
"CUDA_VISIBLE_DEVICES": "1"},
"envFile": "${workspaceRoot}/.env"
}
]
}