vscode远程开发配置
原创2025年8月8日大约 1 分钟
vscode远程开发配置
1. Remote SSH 配置
Remote SSH 的主要配置在 ~/.ssh/config 和 VS Code 的 Remote-SSH 扩展中。
SSH 配置示例
Host myserver
HostName 10.10.1.100
User Jack
Port 22
IdentityFile ~/.ssh/id_rsa
ForwardAgent yes在 VS Code 中打开 Command Palette → Remote-SSH: Connect to Host... → 选择 myserver 即可。
2. VS Code 工作区设置
远程工作区可以在项目目录下的 .vscode/settings.json 配置:
{
"python.pythonPath": "/usr/bin/python3",
"terminal.integrated.shell.linux": "/bin/bash",
"editor.formatOnSave": true
}这部分是 VS Code 的标准设置,远程开发环境会应用这些配置。
3. 开发容器(Dev Containers)配置
当你使用 Remote - Containers 或 Codespaces 时,需要在项目中添加 .devcontainer/devcontainer.json 文件。
devcontainer.json 示例
{
"name": "Python Dev Container",
"image": "python:3.11",
"postCreateCommand": "pip install -r requirements.txt",
"settings": {
"python.pythonPath": "/usr/local/bin/python"
},
"extensions": [
"ms-python.python",
"ms-azuretools.vscode-docker"
],
"forwardPorts": [8000, 5000],
"remoteUser": "vscode"
}主要字段:
name:容器名称image或dockerFile:使用的 Docker 镜像或 DockerfilepostCreateCommand:容器创建后自动执行命令settings:VS Code 设置extensions:自动安装的扩展forwardPorts:端口转发remoteUser:远程用户
4. 调试和任务配置
VS Code 远程调试也使用 .vscode/launch.json 和 .vscode/tasks.json。
launch.json 示例
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "127.0.0.1",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/workspace"
}
]
}
]
}