VS Code 日常开发中的实用配置和技巧记录。包含 SSH 免密连接、项目隔离、Python 参数调试等。
SSH 免密连接设置
服务器端:
-
服务器端
~/.ssh目录权限为700,~/.ssh/authorized_keys文件权限为600 -
服务器的 SSH 配置
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
- 在本机生成rsa私钥公钥。私钥放本地,公钥放服务器
ssh-keygen -t rsa
本地:
- `C:\Users\你的用户名\.ssh\id_rsa`
- `C:\Users\你的用户名\.ssh\id_rsa.pub`
服务器:
- 将公钥(.pub)传入服务器放入以下路径:~/.ssh/authorized_keys
便捷代码:
sftp username@ip
put .ssh/id_ed25519.pub .ssh/authorized_keys
- VS Code 远程连接配置认证文件
配置 ~/.ssh/config,指定私钥路径:
Host myserver
HostName 服务器IP
User 用户名
IdentityFile ~/.ssh/id_rsa # 指向私钥,不是 authorized_keys
创建项目
推荐使用 多 root 工作区 方式管理项目:
- VS Code 菜单 → 文件 → 将文件夹添加到工作区
- 添加完所有相关目录后,文件 → 将工作区另存为,保存为
.code-workspace文件 - 之后双击该文件即可打开完整工作区
这样每个项目独立保存自己的配置、扩展推荐和调试设置。
带参 Debug
如何在 VS Code 中顺滑地调试带参数的 Python 文件?
配置
- 安装依赖包:
pip install debugpy -U - 添加带参数的
launch.json文件配置并选择sh_file_debug
{
"name": "sh_file_debug",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 9501
}
},
- 在 Python 代码前加上这句话
import debugpy
try:
# 5678 is the default attach port in the VS Code debug configurations. Unless a host and port are specified, host defaults to 127.0.0.1
debugpy.listen(("localhost", 9501))
print("Waiting for debugger attach")
debugpy.wait_for_client()
except Exception as e:
pass
使用
- 在终端运行bash命令,并等待debug

- 打上断点,点击调试按钮
sh_file_debug,开始debug


4345

被折叠的 条评论
为什么被折叠?



